How to add responses links in swagger on nestjs? - swagger

I want to create a link from a users get/list method 'id' property to a users/{id} getById method, in OAS3 / nestjs.
Something like this example (under 'Defining Links'):
https://swagger.io/docs/specification/links/
Ive found a 'links' properties in 'schema' object, but I cant set it properly.
Ive searched really hard for explicit definitions about how to set and work with this feature, but seemingly there's no much info about this neither in nestjs official documentation nor other resources.
Ive tried to do some variations of this:
#ApiResponse({
status: 200,
description: 'Finds a user by id.',
schema: { allOf: [{ $ref: getSchemaPath(UserModel) }] },
links: {
operationId: { $ref: 'list' },
},
})
But none of the sets Ive tried to pass under 'links' actually works; it just creates empty links fields in swagger UI.

Related

How to add taxonomies in 11ty?

I'd like to use a json-file that looks somewhat like this
[{
"id": "foo",
"url": "video",
"topic": "Fancy foos"},
{
"id": "bars",
"url": "video",
"topic": "Naughty bars"
}]
as a source for several overview pages that group the entries by topic (I guess it's called taxonomy). What would be a good solution for this? Parse the json, group it with js and create a custom collection for each topic? If so, where would this belong, to a file in the _data folder?
Thx in advance!
I'm not 100% sure I get what you intend, but let me try to help. First, yes, store the file in your _data folder. Let's assume you call it taxonomies.json. This means your code has access to the array as taxonomies.
Next, if you want to build pages based on this data, look at the docs for Create Pages from Data, which describe how to dynamically generate pages based on your data. You could have one per taxonomy. For ex:
---
pagination:
data: taxonomies
size: 1
alias: tax
permalink: "topic/{{ tax.id | slug }}/"
---
content here
Your content needs to be driven by the current taxonomy. I assume you will have a kind of content, like posts, that include a taxonomy? If so, you can create a short code or filter that scans all posts and returns the one with a particular taxonomy in the front data. For example, here's how I get posts that match a category:
{% assign posts = collections.posts | getByCategory: cat %}
And getByCategory is defined in .eleventy.js. The particulars of this part are really dependent on what content you are trying to show.

Swagger UI shows default example for query parameters (instead of provided one), after manually clearing, clicking "cancel", and "try it out"

I have an OpenAPI 3 query parameter, defined with in: query, style: form, explode: true, and with an example value (full definition at the end).
I see a strange behavior with the example value: when first loading the UI, the values displayed are the given example value. If I manually delete it from the text area, click Cancel and click "Try it out" again, I get the default "additionalProp1" value, instead my specific example.
Is there anywhere else I should define the example, or any flag to set?
Full parameter definition:
- name: urlParameters
in: query
description: A list of key value pairs parameters.
style: form
explode: true
schema:
type: object
additionalProperties:
type: string
example: "\r\n{\r\n \"exampleParameter1\": \"string\",\r\n \"exampleParameter2\": \"string\",\r\n \"exampleParameter3\": \"string\"\r\n}"
If the example is moved to the scheme object, it works

Update "favorite" field for a project in Asana API

There's no documentation for updating the favorite field.
Currently I'm trying the following method:
PUT https://app.asana.com/api/1.0/projects/{projectid}
Post data:
{
"data": {
"favorite": true
}
}
There's no error reported. The Asana API returns the project details as the response with the responseCode 200. But when I view the project in Asana the Favorite field has not been updated.
How do I use the API to modify this field?
Resolved this. The Asana app didn't reflect the changes right away. It took a few moments to show the project in the Favorite list.
If anyone else is looking into this undocumented feature please be aware when setting the favorite field to "1" or "0" (the representation in the the API) it returns the 400 responsecode. The value True or False must be processed and not in quotes.

Strapi routes return 404 Not found

I have a problem where all routes in my API return 404 Not found. I followed the Pull from Docker Hub section at strapi/strapi-docker.
What I did, apart from running the images, was creating a new Content type called post containing three fields. If I try GET /post (to get all posts added) I get unauthorized response error. This is expected at this stage. After I check Roles & Permissions to allow the Public role to use the find and findOne routes I instead get a 404 Not found response error even though data has been added.
The dev server does not use any prefix.
post routes for find and findOne looks as the following:
{
"routes": [
{
"method": "GET",
"path": "/post",
"handler": "Post.find",
"config": {
"policies": []
}
},
{
"method": "GET",
"path": "/post/:_id",
"handler": "Post.findOne",
"config": {
"policies": []
}
}
}
There are not many options in the strapi interface to fiddle with so I'm not sure what else to try. I have tried a couple of other installations of strapi. Not sure if that could have messed it up but I vaguely remember trying out strapi/strapi-docker before and getting it to work.
I have stumbled upon this issue many times, and the easiest answer usually is:
Have you published any of your posts?
Strapi has a publishing subsystem which is usually turned on upon the creation of any collection, single type or component.
So when you create any content of any created type, the data is saved as draft and is not publicly available.
Here is my link collection type. It is saved, but not published.
So if you are trying to test an endpoint, but you only have one single data entry and it is set to draft, no data will show up.
No data!
In case of a single type that is not published
This will return a 404!
Publish and, voila ...
This could be one reason why strapi is sending you a 404 or only an empty array!
I've had this issue many times as well, even with published content.
Two additional causes could be:
if your content type is posts try /posts as well as /api/posts (the 2nd usually works for me
Under Settings > Roles (the one under USERS & PERMISSIONS plugins) make sure both Authenticated and Public user roles have find and findOne access to the content type.
One time I was getting the 404 even though I did this for Public...but because I was in the same browser as my logged in admin and needed to update it for Authenticated as well.

Can i post a task to a specific location in a project through asana API?

I'm trying to post a task within a project under a certain section, does anyone have any suggestions as to go about doing it/ is it even possible?
Thanks
Well, you are in luck! We are right now working on improving our support for sections in the API.
To add a task to a given section, you can use the addProject method with a section parameter, which is similar to insert_before or insert_after. An example call would look like POST /tasks/1234/addProject?project=111&section=7865.
Now, that's an extra call you need to make after you create the task, which is a bummer, so we're also working on a way to specify sections when you create the task. But we're literally working on that right now. I'll edit this answer when that exists.
To POST a new task to a project in a specific section (column) hit the workspace URL
https://app.asana.com/api/1.0/workspaces/[workspace-id]/tasks
You need to declare the memberships property in your POST request, the API documentation makes this very confusing.
Here is how it should be:
"memberships": [{
"project": 12345,
"section": 12345
}]
The API documentation makes it seem like you need to also include the name that goes along with the project and section.
Here is their example from the docs which is NOT how it should be done:
[{ project: { id: 1331, name: 'Bugs' }, section: { id: 1123, name: 'P1:' } }]
I found this answer here: https://community.asana.com/t/how-create-task-with-membership-via-api/10481/2

Resources