Remove path aliases from Redoc Documentation - openapi-generator

When you have path aliases in openapi.yaml with $ref, for example
paths:
/municipios/{municipio}:
get:
operationId: getMunicipality
summary: Detalhes sobre Município
parameters:
- in: path
name: municipio
required: true
schema:
type: string
example: évora
allowReserved: true
description: Município
- $ref: '#/components/parameters/json'
responses:
'200':
description: Detalhes do Município
content:
application/json:
schema:
$ref: '#/components/schemas/municipio'
/municipio/{municipio}:
$ref: '#/paths/~1municipios~1%7Bmunicipio%7D'
/municipio/{municipio} is de facto merely a path alias of /municipios/{municipio}
In the documentation both paths rules and response samples are shown in duplicate.
I would like to remove path aliases from redocly documentation, that is, basically remove these duplicates, since I just use them due to backward compatibility.
Is there a way to do that?

No, there is no way to do what you are asking. How would it look if you could? The documentation would break if multiple URIs were assigned to the same GET path in the display. If your intent is to keep an old URI only for backwards compatibility, then you are facing a poor API design.
Unfortunately, backwards compatibility will always be an issue for a REST service. Any time you change a path, you will likely have to version your entire API. There are a few workarounds for this if you are entirely against versioning your API.
Delete the referenced path from your documentation and override the generated api. You can replace the overridden api path with the new path you want to use. Then update your path description to say that the uri also supports the old one.
Remove the reference from the old path and mark it as deprecated instead. You can then continue to support the old path until you feel comfortable removing support for it completely. This will still display both paths, but the deprecated one will be displayed with a strike through.
paths:
/municipios/{municipio}:
get:
operationId: getMunicipality
summary: Detalhes sobre Município
parameters:
- in: path
name: municipio
required: true
schema:
type: string
example: évora
allowReserved: true
description: Município
- $ref: '#/components/parameters/json'
responses:
'200':
description: Detalhes do Município
content:
application/json:
schema:
$ref: '#/components/schemas/municipio'
/municipio/{municipio}:
get:
operationId: getMunicipality
deprecated: true
summary: "obsoleto: Detalhes sobre Município"
description: Este URL está obsoleto. Atualize sua implementação para usar /municipios/{municipio}. O suporte para este URL será removido em 01 de fevereiro de 2023.
responses:
'200':
description: endpoint obsoleto
content:
application/json:
schema:
type: string
example: Este URL está obsoleto. Corrija sua documentação para usar /municipios/{municipio}
I highly recommend option 2. It allows you to inform your consumers of your changes and properly prepare for versioning.

Related

API Platform - External values Swagger are not showing in UI Openapis

According to
https://swagger.io/docs/specification/adding-examples/#external
I have:
# config/api_platform/resources.yaml
App\Entity\Example:
...
responses:
'201':
content:
application/json:
examples:
ExampleA:
externalValue: 'https://127.0.0.1:8000/example/ExampleA.json'
ExampleB:
value:
name: Nino
ExampleB is rendered.
But ExampleA with externalValue is not generated.
Resolved. I found this, externalValue is not supported in Swagger-UI
https://github.com/swagger-api/swagger-ui/issues/5433

Power Automate Custom Connector Test thinks file output is a string

My Web API method returns a binary PDF file in the response body and I've set this in the swagger file in the Custom Connector of Power Automate. However, despite the output being a binary PDF file AND that the property type is "file", the Test function in the Custom Connector UI still thinks its returning a "string" even through it clearly isn't!
Question: Any ideas what I'm doing wrong to make the tester think it's a string?
Here is a screenshot of the issue:
Here is my swagger for the Web API method (take note of the 200 response of schema: {type: file, format: binary}:
swagger: '2.0'
info: {title: xxxx, version: '1.0', description: xxxx}
host: xxxx.azurewebsites.net
basePath: /api
schemes: [https]
consumes: []
produces: []
paths:
/FrontPageGenerator:
post:
description: xxxx
operationId: FrontPageGenerator
summary: FrontPageGenerator
parameters:
- name: body
in: body
required: true
schema: {type: string}
consumes: [application/json]
produces: [application/json, application/pdf]
responses:
'200':
description: Successfully generated composite PDF file
schema: {type: file, format: binary}
'400':
description: Invalid input
schema: {$ref: '#/definitions/GenericJson'}
examples:
application/json: {message: No body}
'406':
description: Not Acceptable Accept Type
schema: {$ref: '#/definitions/BasicError'}
examples:
application/json: {message: Not Acceptable}
definitions:
BasicError:
type: object
properties:
message: {type: string}
GenericJson: {type: object}

SwaggerUI/YAML - reports: Should NOT have additional properties additionalProperty: requestBody [duplicate]

I'm trying to define a post endpoint using swagger, but it isn't allowing the requestBody parameter:
/names/{roster}:
get:
#...
post:
x-swagger-router-controller: names
description: Adds or removes name(s)
operationId: manageNames
parameters:
- name: roster
in: path
description: the roster to use
type: string
required: true
requestBody:
content:
'application/json':
schema:
$ref: '#/definitions/ManageNamesRequest'
when I run npm start, I get this:
API Errors:
#/paths/~1names~1{roster}/post: Additional properties not allowed: requestBody
1 error and 0 warnings
What's wrong with my spec?
You are probably mixing OpenAPI/Swagger 2.0 and OpenAPI 3.0 syntax. Your spec seems to be 2.0, but the requestBody keyword is a 3.0 feature. In 2.0, the request body is defined as a body parameter:
paths:
/names/{roster}:
post:
produces:
- application/json
...
parameters:
- ...
- in: body
name: body
required: true
schema:
$ref: '#/definitions/ManageNamesRequest'
More info: Describing Request Body

Polymorphism in Swagger produces strange error message on discriminator

I'm writing a service with a GET that can return one of five different but closely related types. Since the user wants the option of searching through all five types at once, it has to be a single get call. I'm returning JSON, which can easily handle any type.
I'm trying to do this in Swagger, using their polymorphism feature, which I've never tried before. I'm doing it just like in the example, except under "definitions" instead of "components/schemas". But I'm getting a strange error message that I can't understand. The swagger file is below. The error says this:
Schema error at definitions['Event'].discriminator should be string
It gives this on line 49, which says discriminator:
So, my two questions are: How can I fix it? And will this even give me what I need?
swagger: '2.0'
info:
description: RESTful API to retrieve Titles Metadata
version: 1.0.0
title: Swagger Mystery
schemes:
- https
paths:
/event:
get:
operationId: getEvent
summary: searches names
description: |
Search by names, across all types, or by a specific type.
produces:
- application/json
parameters:
- in: query
name: title
description: name to search for
required: true
type: string
- in: query
name: start
required: false
type: boolean
- in: query
name: type
required: false
type: string
description: |
May be "contest", "partner", "sponsor", or "dancer". If missing, will search for all types.
responses:
'200':
description: search results
# I also don't know why I need to comment these out.
# content:
# application/json:
# schema:
# type: array
# items:
# $ref: '#/definitions/Event'
'400':
description: bad input parameter
definitions:
Event:
type: object
discriminator:
propertyName: eventType
properties:
eventType:
type: string
id:
type: integer
format: int64
name:
type: string
description:
type: string
contests:
type: array
items:
$ref: '#/definitions/Contest'
required:
- id
- name
- description
- contests
- eventType
Contest:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
parentEvent:
type: string
venue:
type: string
required:
- parentEvent
- venue
Dancer:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
eventInvitationDate:
type: string
format: date
venue:
type: string
required:
- eventInvitationDate
- venue
# Sponsor:
# allOf:
# - $ref: '#/definitions/Event'
# - type: object
# properties:
# invitationDate:
# type: string
# format: date
# parentEvent:
# type: string
# partners:
# type: array
# items:
# $ref: '#/definitions/Partner'
Partner:
allOf:
- $ref: '#/definitions/Event'
- type: object
properties:
invitationDate:
type: string
format: date
parentEvent:
type: string
venue:
type: string
required:
- invitationDate
- parentEvent
- venue
# two problems:
# 1. Schema error at definitions['Event'].discriminator
# should be string on line 49 (discriminator:)
# 2. Resolver error:
# e is undefined
# (no line number)
# (This error goes away when I comment out Sponsor.)
The error occurs because you are mixing OpenAPI 2.0 and 3.0 syntax.
Your spec is swagger: '2.0' but the following is 3.0 syntax:
discriminator:
propertyName: eventType
In OpenAPI 2.0, the value of discriminator is the property name:
discriminator: eventType
Also, OpenAPI 2.0 assumes that the possible values of the discriminator property (in this case eventType) are exactly the same as the model names in definitions. That is:
If eventType can be event, partner etc. in lowercase, then the model names must also be in lowercase – event, not Event.
If eventType is some code like e, p, d etc., the model names must be e, p, d etc. instead of Event, Partner etc.
Check out questions for more examples of discriminator usage in OpenAPI 2.0:
Swagger Inheritance and Composition
“discriminator” in polymorphism, OpenAPI 2.0 (Swagger 2.0)
Swagger: variant schema shape dependant on field value

Swagger:Issue with Path parameter

I am try to create a swagger file with the following path:
paths:
/v1/customers/{id}/summary :
However I get the following error right off bat:
API requires path parameter but it is not defined: id
at paths ▹ /v1/customers/{id}/summary
It does not seem to like the 'id' parameter. Could anybody tell me how I could rectify this?
If I drill down on this I see the following:
Details
Object
swaggerError: Object
errors: Array [1]
0: Object
code: "MISSING_API_PATH_PARAMETER"
message: "API requires path parameter but it is not defined: id"
data: "/v1/customers/{id}/summary"
path: Array [2]
warnings: Array [0]
Basically, you're declaring a path that has a path parameter in it, by using path templates. In this case {id} declares a path parameter called id.
When you declare such a path, it means that you have to declare that path parameter as part of the operation.
Take a look at this YAML example:
/pets/{id}:
get:
description: Returns a user based on a single ID, if the user does not have access to the pet
operationId: findPetById
produces:
- application/json
- application/xml
- text/xml
- text/html
parameters:
- name: id
in: path
description: ID of pet to fetch
required: true
type: integer
format: int64
responses:
'200':
description: pet response
schema:
$ref: '#/definitions/pet'
default:
description: unexpected error
schema:
$ref: '#/definitions/errorModel'
You can see there's an {id} in the path, and a corresponding id parameter definition. Without it, the spec won't be valid.

Resources