How generate an API documentation for /api/login_check and /api/token/refresh with NelmioApiDocBundle(4.x) - nelmioapidocbundle

I found a way how generate an API documentation for /api/login_check and /api/token/refresh with NelmioApiDocBundle(4.x).
My project is an API REST with Symfony 5.1.
There is my route.yaml :
api_login_check:
path: /api/login_check
methods: POST
gesdinet_jwt_refresh_token:
path: /api/token/refresh
controller: gesdinet.jwtrefreshtoken::refresh
methods: POST`
and my config/packages/nelmio_api_doc.yaml:
nelmio_api_doc:
models: { use_jms: false }
documentation:
info:
title: BileMoAPI
description: This is an awesome API REST for BileMo!
version: 1.0.0
components:
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWT
in: header
security:
- Bearer: []
paths:
/api/login_check:
post:
tags:
- Login
summary: Login into the api.
requestBody:
content:
application/json:
schema:
properties:
username:
type: string
password:
type: string
type: object
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
token:
type: string
refresh_token:
type: string
'401':
description: Invalid credentials
'400':
description: Invalid JSON.
security: []
/api/token/refresh:
post:
tags:
- Login
summary: Login into the api by refresh token.
requestBody:
content:
application/json:
schema:
properties:
refresh_token:
type: string
type: object
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
token:
type: string
refresh_token:
type: string
'401':
description: An authentication exception occurred.
security: []
areas: # to filter documented areas
path_patterns:
- ^/api(?!(/doc|/doc.json|/token/refresh)$)
#host_patterns:
# - ^/api
And the screenshot of /api/doc :
the screenshot of /api/doc
I hope a can help someone :)

The answer is in the question (Sorry, I'm novice on Stack)

Related

Can i generate a fully structured yaml file from a csv file using Python?

swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key special-key to test the authorization filters."
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
contact:
email: "apiteam#swagger.io"
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "petstore.swagger.io"
basePath: "/v2"
tags:
name: "pet"
description: "Everything about your Pets"
externalDocs:
description: "Find out more"
url: "http://swagger.io"
name: "store"
description: "Access to Petstore orders"
name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes:
"https"
"http"
paths:
/pet:
post:
tags:
- "pet"
summary: "Add a new pet to the store"
description: ""
operationId: "addPet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
"405":
description: "Invalid input"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
put:
tags:
- "pet"
summary: "Update an existing pet"
description: ""
operationId: "updatePet"
consumes:
- "application/json"
- "application/xml"
produces:
- "application/xml"
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Pet object that needs to be added to the store"
required: true
schema:
$ref: "#/definitions/Pet"
responses:
"400":
description: "Invalid ID supplied"
"404":
description: "Pet not found"
"405":
description: "Validation exception"
security:
- petstore_auth:
- "write:pets"
- "read:pets"
securityDefinitions:
petstore_auth:
type: "oauth2"
authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
flow: "implicit"
scopes:
write:pets: "modify pets in your account"
read:pets: "read your pets"
api_key:
type: "apiKey"
name: "api_key"
in: "header"
definitions:
Order:
type: "object"
properties:
id:
type: "integer"
format: "int64"
petId:
type: "integer"
format: "int64"
quantity:
type: "integer"
format: "int32"
shipDate:
type: "string"
format: "date-time"
status:
type: "string"
description: "Order Status"
enum:
- "placed"
- "approved"
- "delivered"
complete:
type: "boolean"
default: false
xml:
name: "Order"
Category:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Category"
User:
type: "object"
properties:
id:
type: "integer"
format: "int64"
username:
type: "string"
firstName:
type: "string"
lastName:
type: "string"
email:
type: "string"
password:
type: "string"
phone:
type: "string"
userStatus:
type: "integer"
format: "int32"
description: "User Status"
xml:
name: "User"
Tag:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
xml:
name: "Tag"
Pet:
type: "object"
required:
"name"
"photoUrls"
properties:
id:
type: "integer"
format: "int64"
category:
$ref: "#/definitions/Category"
name:
type: "string"
example: "doggie"
photoUrls:
type: "array"
xml:
name: "photoUrl"
wrapped: true
items:
type: "string"
tags:
type: "array"
xml:
name: "tag"
wrapped: true
items:
$ref: "#/definitions/Tag"
status:
type: "string"
description: "pet status in the store"
enum:
"available"
"pending"
"sold"
xml:
name: "Pet"
ApiResponse:
type: "object"
properties:
code:
type: "integer"
format: "int32"
type:
type: "string"
message:
type: "string"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"

Azure API Management ignores formData input parameters

I have an API built using ServiceStack which implements the Swagger UI and OpenAPI 2.0 specification.
I have several POST methods that use formData inputs and these show in the Swagger UI as individual input textboxes as shown below:
The OpenApi output that Swagger generates looks like this for the input parameters:
'/api/{Version}/apimethod':
post:
tags:
- API
summary: Get a values from an API.
description: Notes here
operationId: UniqueOperationId
consumes:
- application/x-www-form-urlencoded
produces:
- application/json
parameters:
- name: Field1
in: formData
description: Field1
type: number
format: double
required: false
x-nullable: false
- name: Field2
in: formData
description: Field2
type: integer
format: int32
required: false
x-nullable: false
- name: Field3
in: formData
description: Field3
type: integer
format: int32
required: false
x-nullable: false
- name: Field4
in: formData
description: Field4
type: integer
format: int32
required: false
x-nullable: false
- name: Field5
in: formData
description: Field5
type: number
format: double
required: false
x-nullable: false
- name: Field6
in: formData
description: Field6
type: integer
format: int32
required: false
x-nullable: false
- name: Field7
in: formData
description: Field7
type: integer
format: int32
required: false
x-nullable: false
- name: Field8
in: formData
description: Field8
type: integer
format: int32
required: true
x-nullable: false
- name: Version
in: path
description: Version of the API to call
type: integer
format: int32
required: true
x-nullable: false
responses:
'200':
description: Success
schema:
$ref: '#/definitions/GetApiMethodResponse'
'400':
description: Your request was not understood
schema:
$ref: '#/definitions/GetApiMethodResponse'
'500':
description: 'Oops, something broke'
schema:
$ref: '#/definitions/GetApiMethodResponse'
deprecated: false
parameters:
- $ref: '#/parameters/Accept'
If I import the OpenAPI specification into the Azure API Management service to create an new API facade it ignores the formData inputs.
I was expecting that it would list all of the individual inputs and their descriptions in the Azure API Management portal just like the Swagger UI does.
Am I doing something wrong or does the Azure API Management service not list individual formData input parameters the same as the Swagger UI?
My API methods do have alot of parameters and its not very helpful to the end users of the Azure API Management portal to have to fill in a JSON payload which has no descriptions as to what each property on the JSON payload does.
According to your description, I assume your purpose is importing OpenAPI specification into the Azure API Management service and keeping the parameter description in the apim page.
I find that 'post' request can add query parameter but 'get' request can't. After adding some parameters, I get following view. I added 3 parameters, I added description of each parameter but none of them showed in this page.
After that, I exported the api and I got a file named hello.openapi.yaml, here is the detail. I can modify the parameters in this file and then import it in an Api instance.
openapi: 3.0.1
info:
title: hello
description: ''
version: '1.0'
servers:
- url: http://tinyapim.azure-api.net/index
paths:
/hello:
get:
summary: hello
operationId: hello
responses:
'200':
description:
/getJsonObject:
get:
summary: getJsonObject
operationId: getjsonobject
responses:
'200':
description:
/sendpost:
post:
summary: sendPost
operationId: sendpost
parameters:
- name: userName
in: query
description: description1
schema:
enum:
- hello
type: string
- name: userId
in: query
description: required param
required: true
schema:
type: ''
- name: age
in: query
schema:
type: int
responses:
'200':
description:
components:
securitySchemes:
apiKeyHeader:
type: apiKey
name: Ocp-Apim-Subscription-Key
in: header
apiKeyQuery:
type: apiKey
name: subscription-key
in: query
security:
- apiKeyHeader: [ ]
- apiKeyQuery: [ ]
I think these are all Apim can do on your case. Wish it would help.

What is the correct way test the file upload through swagger-client?

I need to write a valid test of a file upload through swagger client but I can not figure out what I'm doing wrong or possible solutions
const requestBody = {
name: 'USUÁRIO TESTE',
cpf: 'PROCESSO DE TESTE/DEPLOY KAER-MORHEN',
email: 'POR FAVOR IGNORE ESTE E-MAIL',
phone: 'OBRIGADO',
id: 'cj2c3rtea00010epfu0sfdhf7',
back: tmp.fileSync({ prefix: 'document-', postfix: '.jpg' }).name
}
return client.apis.documents.sendDocumentsEmail(undefined, {
requestBody
})
.should.be.fulfilled()
.then(({ status, body }) => {
status.should.be.eql(200)
body.should.be.Object()
})
I'm also using Multer as middleware, and when I send the tmp file or creating a file with fs it doesn't get recognized and the attribute ends up beeing treated as a string.
What would be the simplest way to send a valid multipart/form-data with a valid file using swagger-client?
/documents/upload:
x-middlewares:
- "multer"
post:
tags:
- "documents"
- "kaermorhen"
summary: "Upload documents"
x-swagger-router-controller: "document.controller"
operationId: "sendDocumentsEmail"
requestBody:
description: "Documents upload"
required: true
x-name: "body"
content:
multipart/form-data:
schema:
type: "object"
required:
- "id"
properties:
id:
type: "string"
name:
type: "string"
cpf:
type: "string"
email:
type: "string"
phone:
type: "string"
front:
type: string
format: binary
back:
type: string
format: binary
residence:
type: string
format: binary

Swagger auto generate documentation yaml format?

There is sequelize auto where in you can generate generate models for SequelizeJS via the command line. I wanted to know if there is a way to auto generate api swagger documentaion in .yaml fromat based from my database using command line. Thanks . your help would really be appreaciated.
swagger api documentaion , is there a way to auto generate it instead og typing each CRUD from my database which is a hassle. Thanks
swagger: "2.0"
info:
version: 1.0.0
title: myApp1.0
description: my Application 1.0
basePath: /api/v1
tags:
- name: Examples
description: Simple example endpoints
- name: Products
description: Simple products endpoints
- name: Countries
description: Simple countries endpoints
- name: Users
description: Simple Users endpoints
- name: Specification
description: The swagger API specification
consumes:
- application/x-www-form-urlencoded
- application/json
produces:
- application/json
definitions:
ExampleBody:
type: object
title: example
required:
- name
properties:
name:
type: string
description: The example name
ProductsBody:
type: object
title: products
required:
- name
properties:
name:
type: string
description: The products name
CountriesBody:
type: object
title: countries
required:
- name
- sortname
properties:
name:
type: string
description: The countries name
sortname:
type: string
description: The countries sortname
UsersBody:
type: object
title: users
required:
- user_id
- firstname
- lastname
- about
- username
- email
- password
- last_login
- status
properties:
name:
type: string
description: The users firstname
sortname:
type: string
description: The users lastname
paths:
/examples:
get:
tags:
- Examples
description: Fetch all examples
responses:
200:
description: Returns all examples
post:
tags:
- Examples
description: Create a new example
parameters:
- name: example
in: body
description: number of items to skip
required: true
schema:
$ref: "#/definitions/ExampleBody"
responses:
200:
description: Returns all examples
/examples/{id}:
get:
tags:
- Examples
parameters:
- name: id
in: path
required: true
description: The id of the entity to retrieve
type: integer
responses:
200:
description: Return the example with the specified id
404:
description: Example not
/products:
get:
tags:
- Products
description: Fetch all products
parameters:
- name: offset
in: query
required: true
description: The offset of the pagination
type: integer
- name: limit
in: query
required: true
description: The limit of the pagination
type: integer
responses:
200:
description: "successful operation"
#security:
#- api_key: []
post:
tags:
- Products
description: Create a new example
parameters:
- name: example
in: body
description: number of items to skip
required: true
schema:
$ref: "#/definitions/ProductsBody"
responses:
200:
description: Returns all products
security:
- api_key: []
/products/{id}:
get:
tags:
- Products
parameters:
- name: id
in: path
required: true
description: The id of the entity to retrieve
type: integer
responses:
200:
description: Return the products with the specified id
404:
description: Products not
security:
- api_key: []
/countries:
get:
tags:
- Countries
description: Fetch all countries
parameters:
- name: token
in: header
required: false
description: The header token
type: string
- name: offset
in: query
required: false
description: The offset of the pagination
type: integer
- name: limit
in: query
required: false
description: The limit of the pagination
type: integer
responses:
200:
description: "successful operation"
#security:
#- api_key: []
post:
tags:
- Countries
description: Create a new Country
parameters:
- name: token
in: header
required: false
description: The header token
type: string
- name: country
in: body
description: number of items to skip
required: true
schema:
$ref: "#/definitions/CountriesBody"
responses:
200:
description: Create Country
# security:
# - api_key: []
/users:
get:
tags:
- Users
description: Fetch all users
parameters:
- name: token
in: header
required: false
description: The header token
type: string
- name: offset
in: query
required: false
description: The offset of the pagination
type: integer
- name: limit
in: query
required: false
description: The limit of the pagination
type: integer
responses:
200:
description: "successful operation"
post:
tags:
- Users
description: Create New User Accounts
parameters:
- name: Users
in: body
description: number of items to skip
required: true
schema:
$ref: "#/definitions/UsersBody"
responses:
200:
description: Create User Accounts
security:
- api_key: []
/users/{id}:
delete:
tags:
- Users
parameters:
- user_id: id
in: path
required: true
description: The id of the entity to be deleted
type: integer
responses:
200:
description: Returns a successful delete
404:
description: Error
security:
/spec:
get:
tags:
- Specification
responses:
200:
description: Return the API specification
securityDefinitions:
#petstore_auth:
# type: "oauth2"
# authorizationUrl: "http://petstore.swagger.io/oauth/dialog"
# flow: "implicit"
# scopes:
# write:pets: "modify pets in your account"
# read:pets: "read your pets"
api_key:
type: "apiKey"
name: "api_key"
in: "header"

AWS Lambda based serverless Express app returns 500 internal server error

I'm trying to create a AWS Lambda and ExpressJS based serverless app. However when I test the generated API url using postman it returns 500 "Internal server error".
I'm following this guide.
simple-proxy-api.yaml
---
swagger: 2.0
info:
title: AwsServerlessExpressApi
basePath: /prod
schemes:
- https
paths:
/:
x-amazon-apigateway-any-method:
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:101010101010:function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
options:
consumes:
- application/json
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
get:
summary: "Arrived at the root of the API"
description: "Root API reached. This is for testing."
produces:
- application/json
responses:
200:
description: 200 response
schema:
type: string
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
/friends:
get:
summary: "List friends"
description: "See list of friends here"
produces:
- application/json
responses:
200:
description: 200 response
schema:
type: array
items:
type: object
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
options:
consumes:
- application/json
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
/{proxy+}:
x-amazon-apigateway-any-method:
produces:
- application/json
parameters:
- name: proxy
in: path
required: true
type: string
responses: {}
x-amazon-apigateway-integration:
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:101010101010:function:${stageVariables.ServerlessExpressLambdaFunctionName}/invocations
httpMethod: POST
type: aws_proxy
options:
consumes:
- application/json
produces:
- application/json
responses:
200:
description: 200 response
schema:
$ref: "#/definitions/Empty"
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
get:
summary: "Arrived at the root of the API"
description: "Root API reached. This is for testing."
produces:
- application/json
responses:
200:
description: 200 response
schema:
type: string
headers:
Access-Control-Allow-Origin:
type: string
Access-Control-Allow-Methods:
type: string
Access-Control-Allow-Headers:
type: string
x-amazon-apigateway-integration:
responses:
default:
statusCode: 200
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'https://example.com'"
passthroughBehavior: when_no_match
requestTemplates:
application/json: "{\"statusCode\": 200}"
type: mock
x-amazon-apigateway-binary-media-types:
- '*/*'
definitions:
Empty:
type: object
title: Empty Schema
index.js
'use strict'
var express = require('express');
var app = express();
var router = express.Router();
router.get('/', function (req, res) {
console.log('inside main routee');
res.send('Hello to express world!');
console.log('going out of main routee');
});
router.get('/friends', function (req, res) {
console.log('inside friends routee');
res.send({
status: "success",
data: [
{"id": 3, "name": "Alex"},
{"id": 4, "name": "TJ"}
]});
console.log('going out of friends routee');
});
app.use('/', router);
// app.listen(3000, () => console.log('Example app listening on port 3000!'));
module.exports = app;
console.log('Exported server');

Resources