In strapi what are api templates for? - strapi

I've started playing with strapi to see what it can do.
When generating an api through strapi studio, it generates a set of base files to handle the model and api calls.
In the entity folder (e.g. article), there's a templates/default folder created with a default template. For an article entity, I get a ArticleDefault.template.json file with this:
{
"default": {
"attributes": {
"title": {},
"content": {}
},
"displayedAttribute": "title"
}
}
In strapi studio I also then add additional templates for each entity, given it multiple templates.
The command line api generator does not create the templates folder.
I couldn't find anything about it in the documentation I read.
What are the generated templates for?
When would I use them, and how would I choose a particular template if I have multiple?

I'm one of the authors of Strapi.
A template is like a schema of data. Let’s take a simple example. You have an API called Post, sometimes your post have a title and a content attribute, but other times, your post have a title, a subtitle, a cover and a content attribute. In both cases, we’re talking about the same API Post but your schema of data is different. That’s why we implemented the templates! Your needs could be different for the same content.
Then, as you said the CLI doesn't generate a template folder in project. The Studio doesn't use the same generator as the CLI but the behavior of your API is the same.

Related

xmldoc <see> with cref that refers to a class under a separate csproj

We have an SDK project that includes a test engine. These live under two different csproj's. So we have SDK.csproj and TestEngine.csproj where SDK.csproj is a ProjectReference.
I have a DocFx project set up that builds metadata for these two separately, with docfx.json metadata that looks like this:
{
"src": [
{
"src": "../../sdk",
"files": ["csharp/SDK/**/*.cs"]
}],
"dest": "reference/SDK"
},
{
"src": [
{
"src": "../../sdk",
"files": ["csharp/TestEngine/**/*.cs"]
}],
"dest": "reference/TestEngine"
}
This way I can set up TOC's to put these documentation trees under separate tabs.
However, I cannot use a cref in TestEngine xml docs that refers to a class from SDK. I get an error like this from DocFX build:
Warning:[MetadataCommand.ExtractMetadata]Invalid cref value "!:SDK.SDKClass" found in triple-slash-comments for TestEngineClass, ignored.
I can imagine why this fails - DocFX is generating the metadata for TestEngine alone so it doesn't know about the SDK classes or how to link to them. Is there a way I can change the configuration so that I can keep these two projects separate (under separate TOC's) in the final website but still link from TestEngine to SDK classes?
I realized that using # and/or xref tags as described in the DocFx documentation do resolve to links properly in the generated web pages. So that gets me a lot of what I want. However, it's not a complete solution as other generated references do not resolve to links. For example, if a TestEngine method has a parameter of type SDK.SDKClass, the generated docs won't make a link for SDKClass where it appears on the parameter documentation. So I'm still wondering if there is another solution.

Extract Graphql queries sent by a browser application with Apollo client

I am trying to simplify the process of exporting GraphQL queries sent by my application for documentation purposes. For the record, I want to be able to paste those queries into Postman collections.
Here are my different approaches:
Relying on .graphql files: first it's still very difficult to setup with a full fledged TypeScript + Webpack + Babel setup (using Next.js). Anyway, it does not provide variables, so you only have half the query.
Relying on the network tab. From there, we can copy queries content and import into Postman. Combined with Cypress it could provide an awesome workflow. It works OK, but Apollo Client will send queries as JSON objects, difficult to interpret
I tried to use the "application/graphql" content-type. It's way more readable and available in Postman. BUUUT it is non-standard, and thus not available in Apollo client.
So my question is rather open, but what are the possibilities to enable extracting graphql queries (and variables) sent by my browser and inject them into Postman?
Most promising solution is enabling "application/graphql" client side, or converting the JSON representation back to a string representation. But I could explore another possibility (eg using Apollo Engine as an intermediate)
A way to do this is to use the apollo CLI tool. It includes a client:extract command that extracts all of the GraphQL operations/documents in your application into a file. You run the tool on your JS(X)/TS(X) files and it extracts the GraphQL documents into a file that looks like this (this output is the result of pointing the tool at a single file containing a single query):
{
"version": 2,
"operations": [
{
"signature": "b4f318e6aebcc3631bc88eedef09c6001bb8c310917e97ee6df4a99e17c3c056",
"document": "query BootstrapQuery{user:viewer{__typename delivery_time_1 delivery_time_2 devices{__typename fcm_token id notification{__typename enabled}}has_password id label location name next_delivery_string oauths{__typename email id name picture provider}plan plan_billing_service plan_expires plan_since plan_will_renew profile_picture recovery_email timezone username}}",
"metadata": {
"engineSignature": ""
}
}
]
}
You can then use that file however you want.
In my case, I use this tool to publish an allow-list of operations to Hasura. I'm not sure what you mean by injecting queries into Postman, but I think this tool may provide you with an automated start that would be an improvement over manual copy/pasting.

How to exclude assets from apostrophe-site-map coming from AWS S3

This is a very plugin specific question to ask. But I am using this plugin https://github.com/apostrophecms/apostrophe-site-map which is for integration with Apostrophe CMS and I have no idea where else to ask this question.
https://docs.apostrophecms.org/apostrophe/
In the documentation for the sitemap generator, there is this example of how to exclude certain types of content.
{
'apostrophe-site-map': {
excludeTypes: [ 'apostrophe-blog-post' ]
}
}
But I am trying to stop all of the uploads from showing up on the sitemap. PDFs and JPGs etc.. Currently every single asset that has been uploaded from the cms to AWS S3 is showing up. We want to stop this from happening.
Is there a way to do this with the plugin API or do we need another solution to generate the sitemap?
Or is there an alternative way to stop this (without using Cloudfront) on S3 side?
Any ideas are welcome!
Yes, you can do that by adding them to the excludeTypes option of apostrophe-site-map, like this:
// in app.js where you configure the module
apostrophe-site-map: {
// singular names, not module names, these are used in the type
// property of each doc
excludeTypes: [ 'apostrophe-image', 'apostrophe-file' ]
}
They are showing up in the sitemap because they have a _url property but you can add them to the list to be excluded. It is probable that we should do this by default for images. PDFs, I'm not so sure about the best default.

Amadeus Hotel API Images

Is there any way for me to get Hotel's room images from your self-service API? Does the enterprise API support this functionality?
Based on your own documentation this type of information should be available through the following tag:
"media": [{
"uri": "string"
}]
but I'm not getting this tag using any of the search criteria that I'm currently testing with.
EDIT
This question was related to the Hotel Search API v1 in the new version available (v2) the view=FULL is set by default.
You need to add:
view=FULL
In your query to get the media.
For example:
https://test.api.amadeus.com/v1/shopping/hotel-offers?cityCode=LON&view=FULL
Note: we only have a few images in the test environment, most of the responses contain a fake image.

Hide author email address from Google Sheets API

Google Sheets allows publishing any spreadsheet to web. Doing so exposes the data contained in the published spreadsheet for access via variety of APIs, such as Google Sheets API.
This is all fined and good, except for one thing. Accessing the a published worksheet via API, returns email addresses of the users who have contributed to that worksheet.
For example a request like this:
https://spreadsheets.google.com/feeds/cells/[key]/[sheetId]/public/basic?alt=json
Among other information, will also return this:
"author": [ {
"name": {
"$t": "***"
},
"email": {
"$t": "***#***.com"
}
} ],
The *** in the above snippet are real Google account names and emails.
Is there a way, either via document properties or via generic Google Account properties, to disable publishing of your email address via public APIs?
There is no way to hide that information in that spreadsheet.
However, here is a workarround:
copy the sheet contents to another spreadsheet, and publish that other spreadsheet. Copying can be done several ways:
You can make a manual copy, which will preserve everything including images, but is harder to maintain in sync.
use the =ImportRange formula to import values automatically into the copy. that handles changes but doesnt handle all formatting and wont work if images change (unless they are placed using =image formula).
=IMPORTRANGE("1z5afM6Wn-8RKsdUpTPicU0d81YCWX4bqzgKIna1uep0","Instructions!A1:E") for example will copy all content in columns A to E into your sheet.
In the published sheet make that "File:Spreadsheet settings" is set to "Recalculation: on change and every minute".
A more detailed example of using importRange is in this blogpost I made, see the part about importRange to copy the "instructions" sheet to other sheets: http://zigmandel.blogspot.com/2015/09/how-i-crowd-translated-my-product-tour.html
3. have an apps script with a trigger to copy the entire sheets into the published spreadsheet. that will preserve everything but is a little more code to delete the old sheets and copy the new ones over.
And of course, the email you use for making those copies (manually or by script) needs be one you don't mind publishing.

Resources