In swagger's documentation using OpenApi specification, you can wrap schema in parameter to content with application/json:
parameters:
- in: query
name: filter
# Wrap 'schema' into 'content.<media-type>'
content:
application/json: # <---- media type indicates how to serialize / deserialize the parameter content
schema:
type: object
properties:
type:
type: string
color:
type: string
to send objects like this filter={"type":"t-shirt","color":"blue"}.
How to do it in swagger-php?
The swagger-editor and swagger-ui have added support for http://swagger.io/docs/specification/describing-parameters
The swagger-php library has added support too, it will be part of the 3.0.4 release.
Related
I have a Typo3 page that works with two URL parameters, "manuscript" and "type" (e.g. localhost/my-page?manuscript=samplemanuscript&type=description). "manuscript" is a mandatory parameter, while "type" is optional.
I use Route Enhancers to get rid of cHash in the URL. So I have created a yaml file to configure it.
This configuration works fine without "defaults" section with both parameters in place, but when I add the defaults section to make "type" parameter optional, the URL localhost/my-page/samplemanuscript works fine, but localhost/my-page/samplemanuscript/description shows me the 404 error. Any ideas what's wrong with it?
I use Typo3 v10.4
routeEnhancers:
ManuscriptHierarchy:
type: Simple
limitToPages: [13]
routePath: '/{manuscript}/{type}'
defaults:
type: ''
aspects:
manuscript:
type: StaticValueMapper
map:
samplemanuscript: samplemanuscript
samplemanuscript2: samplemanuscript2
type:
type: StaticValueMapper
map:
transcription: transcription
description: description
P.S.
For debugging purposes, is there any appropriate way to check the final resolved URL (when I visit localhost/my-page/samplemanuscript/description)?
The solution looks strange to me but it works by adding requirements:
routeEnhancers:
ManuscriptHierarchy:
type: Simple
limitToPages: [13]
routePath: '/{manuscript}/{type}'
defaults:
type: ''
requirements:
manuscript: '^(?:samplemanuscript|samplemanuscript2)$'
type: '^(?:description|transcription)$'
aspects:
manuscript:
type: StaticValueMapper
map:
samplemanuscript: samplemanuscript
samplemanuscript2: samplemanuscript2
type:
type: StaticValueMapper
map:
transcription: transcription
description: description
I am using the swagger-codegen Spring generator to generate the API classes using a YAML API definition. I am describing post request with multiple parameters in the body like this:
paths:
/api/test:
post:
...
requestBody:
content:
application/json:
schema:
properties:
firstName:
type: string
lastName:
type: string
This generates a method in the ApiDelegate with the signature ResponseEntity test(Body body). However, when describing multiple post methods like this, the subsequent generated signatures have parameters of type Body1, Body2, ... . With Swagger 2.0, it was possible to name the RequestBodies. Can I do something similar with V3?
Thanks for your help!
Kind regards
Hi I want to create AWS::Pinpoint::PushTemplate using cloudformation template and I am following this link: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pinpoint-pushtemplate.html.
Type: AWS::Pinpoint::PushTemplate
Properties:
Default:
Action: OPEN_APP
Body: FirstName - {{firstName}}, LastName - {{lastName}}
Title: Title
DefaultSubstitutions:
firstName: default
lastName: default
Tags:
project: project
tashi: "Pinpoint Template"
TemplateName: template_name
I am getting type validation error for`DefaultSubstitutions: Property validation failure: [Value of property {/DefaultSubstitutions} does not match type {String}]
According to docs DefaultSubstitutions is a String.
However, in your case, you set it up as map:
DefaultSubstitutions:
firstName: default
lastName: default
Maybe have to try using it as json string:
DefaultSubstitutions: "{\"firstName"\:\"default\", \"lastName"\:\"default\"}"
I want to define an enum value in the query string parameter of a function in an OpenAPI specification.
Here is an example of how I specify the parameter in my OpenAPI specification (yaml):
openapi: 3.0.0
info:
description: Vends sodas
version: 1.0.0
title: VendingMachineService
paths:
/soda/{bill}:
get:
summary: Provides a soda for a provided amount of money
description: Provides a soda for a provided amount of money
operationId: getSoda
parameters:
- name: bill
in: path
description: Money (e.g. one, two, five)
required: true
schema:
$ref: "#/components/schemas/Bill"
responses:
"200":
description: Success
content:
application/json:
schema:
$ref: "#/components/schemas/Result"
"404":
description: Templates for Source not found
servers:
- url: http://localhost:8080/
components:
schemas:
Bill:
type: string
enum:
- one
- two
- five
Result:
type: string
The key part of the OpenAPI spec is that I define the enum in a schema object at the bottom, type string, and refer to it in the parameters section of the function, also defining it as part of the path /{bill}
I then use openapi-generator to generate the spring server:
openapi-generator generate -i ~/vending-machine.yaml -g spring -o ~/output
I then spin up the server (importing the project into Intellij and running in a spring-boot configuration) and go to localhost:8080/ to open the Swagger UI. I try to exercise the api and get the following error:
{ "timestamp": "2019-03-29T15:43:14.737Z", "status": 400,
"error": "Bad Request", "message": "Failed to convert value of type
'java.lang.String' to required type 'org.openapitools.model.Bill';
nested exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type [java.lang.String] to type
[#javax.validation.constraints.NotNull
#io.swagger.annotations.ApiParam #javax.validation.Valid
#org.springframework.web.bind.annotation.RequestParam
org.openapitools.model.Bill] for value 'null'; nested exception is
java.lang.IllegalArgumentException: No enum constant
org.openapitools.model.Bill.null", "path": "/soda/%7Bbill%7D" }
(501 Not Implemented expected)
What is the proper way to define the query params & enum in the OpenAPI spec to use enum values?
I have a definition of a report object. I have another definition of reports object that has an array of report objects (via a $ref).
In the report definition, I have an example defined, which works fine in swagger UI.
In the reports definition, I want it to use the example from the report definition.
How can I do this? I've tried several things using $ref, the closest I got was what I have in the following YAML...
definitions:
report:
type: object
properties:
ID:
type: number
format: int
description: "DB record ID of the report."
readOnly: true
ErrorContent:
type: string
description: "The actual problem or error infomation for this report. This can be exception stack, etc."
readOnly: true
UserComments:
type: string
description: "Any user comments collected by the app and submitted with the report."
readOnly: true
ReportedBy:
type: string
description: "The person using the app when it triggered the error this report is for."
readOnly: true
ReportedDateTime:
type: string
description: "The date/time the report was submitted."
readOnly: true
required:
- ID
- ErrorContent
- ErrorType
- UserComments
- ReportedBy
- ReportedDateTime
example:
ID: 11367
ErrorContent: "Operation is not valid due to the current state of the object."
ErrorType: "Exception"
UserComments: "Was clicking this and that and then Boom!"
ReportedBy: "domain\\name"
ReportedDateTime: "2016-01-19 14:07:00"
reports:
properties:
message:
type: string
reports:
type: array
items:
$ref: '#/definitions/report'
example:
message: "success"
reports:
- $ref: '#/definitions/report'
However, in Swagger UI, the above results in...
{
"message": "success",
"reports": [
{
"$ref": "#/definitions/report"
}
]
}
One interesting note, in Swagger UI, when I look at the model view, it does have all of report even with descriptions.
This behavior is correct--the examples section cannot be referenced with a JSON pointer. See the OAI Specification for what is currently supported.
If you feel this is a common use case, please open an issue on the spec repository.