How to get an image response in Swagger 3.0 - swagger

Image response is not coming from swagger,
/Legends/icons:
get:
tags:
- Legend Controller
summary: Get legend icon
description: Proxy for icon request for legends which use one.
operationId: GetLegendIcon
parameters:
- name: IconUrl
in: query
schema:
type: string
nullable: true
responses:
'200':
description: ''
content:
image/png: {}
'500':
description: ''
security:
- bearerAuth: []
Error : can't parse JSON. Raw result:
This is my swagger version openapi: 3.0.3
enter image description hereenter image description here
I am expecting image response

Related

Does response status code make sense for multiple media types for error status codes as per OpenAPI 3 (Swagger) spec

If we follow the OAS3 spec for Response here we can see that each response status code can have multiple media types and each media type in turn has a schema particular to it.
UseCase : For example oas3 example below, we can see 200 has a binary stream response but 400 has 3 media-types:application/json, application/xml, text/plain.
So is the client expected to request accept-type header with all the media-types mentioned below. How can we have specific media-type for 400 response code, or basically how we can convey to the REST Service to respond with media type as application/xml when its a 400 bad request and if 200 is returning a binary stream.
Does this OAS3 response multiple media-type make sense for Client/Server Errors. If yes then whats the accept-type set for expecting, say "application/xml" for 400 bad request.
Please refer the below swagger UI snap. Where we see a drop-down for the media-types for error code as well. But when we try out executing the rest operations, the accept header is only populated as per the 200 status code's media-type
openapi: 3.0.0
info:
version: "1.0"
title: Resource
description: Resource service
paths:
/resource:
get:
summary: getResource
description: getResource
operationId: get-resource
responses:
"200":
description: a binary document to be returned
content:
application/octet-stream:
schema:
type: string
format: binary
"400":
description: Bad Request
content:
application/json:
schema:
$ref: "#/components/schemas/Error400Element"
application/xml:
schema:
$ref: "#/components/schemas/Error400Element"
text/plain:
schema:
$ref: "#/components/schemas/Error400Element"
"500":
description: Internal Server Error
content:
application/json:
schema:
$ref: "#/components/schemas/Error500Element"
application/xml:
schema:
$ref: "#/components/schemas/Error500Element"
text/plain:
schema:
$ref: "#/components/schemas/Error500Element"
servers:
- url: http://localhost:8088/
components:
schemas:
Error400Element:
type: object
required:
- name
properties:
name:
type: string
number:
type: integer
Error500Element:
type: object
properties:
number:
type: integer
flag:
type: boolean
EDIT : modified the OAS3 spec and the SwaggerUI

Swagger : Get method using body is not working also changed into the query, path, header still not working

i am making openapi.yaml till now as well as deploying my test API's on the google cloud endpoints is working but now i made some changes i am sending parameter in body to the get api (e.g email) and getting some response but actually on the local it is working fine with postman after deploying openapi.yaml file it is not working on the google cloud endponits portal
So, anybody has any solution or answers for this so please help me
For safety i am also sharing error screenshot also y code snippet
"/api/getRecords":
get:
description: "Get All Records Details."
operationId: "getRecords"
produces:
- "application/json"
parameters:
- description: "Message to getRecords"
in: query
name: getRecords
type: object
required: false
schema:
$ref: "#/definitions/echoMessage"
responses:
200:
Also,
Try your code like this :
# [START swagger]
swagger: "2.0"
info:
description: "A simple Google Cloud Endpoints API example."
title: "Endpoints Example"
version: "1.0.0"
host: "abc.appspot.com"
# [END swagger]
parameters:
email:
name: email
in: query
type: string
required: true
Then use shorthand syntax in the path:
path:
"/api/getRecords":
get:
description: "Get All Records Details."
operationId: "getRecords"
parameters:
- $ref: "#/parameters/email"
responses:
200:
description: "Get records details"
schema:
$ref: "#/definitions/postMessage"
It will work.

Swagger/open api 3.0 links not rendered properly [duplicate]

I'm writing an Open API 3.0 spec and trying to get response links to render in Swagger UI v 3.18.3.
Example:
openapi: 3.0.0
info:
title: Test
version: '1.0'
tags:
- name: Artifacts
paths:
/artifacts:
post:
tags:
- Artifacts
operationId: createArtifact
requestBody:
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
201:
description: create
headers:
Location:
schema:
type: string
format: uri
example: /artifacts/100
content:
application/json:
schema:
type: object
properties:
artifactId:
type: integer
format: int64
links:
Read Artifact:
operationId: getArtifact
parameters:
artifact-id: '$response.body#/artifactId'
/artifacts/{artifact-id}:
parameters:
- name: artifact-id
in: path
required: true
schema:
type: integer
format: int64
get:
tags:
- Artifacts
operationId: getArtifact
responses:
200:
description: read
content:
application/octet-stream:
schema:
type: string
format: binary
renders a link like this:
Is this expected? I ask because the operationId is exposed on the UI and parameters is shown as a JSON reference make it seem like something is not displaying properly. I would have expected a hyperlink or something to take me to the appropriate section in the Swagger web page that corresponds to the API being referenced by the link.
Yes this is how Swagger UI currently renders OAS3 links. Rendering of links is one of the things on their OAS3 support backlog:
OAS 3.0 Support Backlog
This is a collection ticket for OAS3 specification features that are not yet supported by Swagger-UI.
...
[ ] Links can't be used to stage another operation
[ ] Link-level servers are not available for executing requests

How to define a query parameter with name but no value?

I'm creating Swagger documentation for an URL that looks like this:
mysite.local.com/mylink?callback&service=someservicename&currency=USD
As you can see, the callback parameter in the query string has a name but no value. How do I describe this parameter in Swagger?
Here's the YAML code I'm using:
swagger: "2.0"
info:
title: My API
description: Documentation of webservices Used
version: 1.0.0
host: mysite.local.com
basePath: /
schemes:
- https
paths:
/mylink:
get:
summary: sometext
description: Optional extended description in Markdown.
produces:
- application/json
responses:
200:
description: OK
parameters:
callback:
I found in the doc that you can specify a parameter that is in the "query", but i'm pretty sure you'll have to give it a value (ie : ?callback=true)
Example :
paths:
/mylink:
get:
summary: sometext
description: Optional extended description in Markdown.
produces:
- application/json
responses:
200:
description: OK
parameters:
- name: callback
in: query
type: boolean

How to define path and formData parameters for the same operation in OpenAPI 2.0?

I have an image upload endpoint that looks like /test/{id}/relationships/image. I want to describe this endpoint using OpenAPI 2.0 (Swagger 2.0).
The endpoint has both path and formData parameters. I tried the following:
swagger: '2.0'
info:
title: API
version: 1.0.0
host: api.server.de
schemes:
- https
produces:
- application/json
paths:
'/test/{id}/relationships/image':
post:
operationId: addImage
consumes:
- multipart/form-data
parameters:
- in: path
name: id
required: true
schema:
type: integer
format: int32
- in: formData
name: file
type: file
required: true
description: The file to upload.
- in: formData
name: metadata
type: string
required: false
description: Description of file contents.
responses:
'202':
description: Uploaded
But Swagger Editor shows errors:
Schema error at
paths['/test/{id}/relationships/image'].post.parameters[0].in should
be equal to one of the allowed values allowedValues: body, header,
formData, query Jump to line 17
Schema error at
paths['/test/{id}/relationships/image'].post.parameters[0] should NOT
have additional properties additionalProperty: schema, in, name,
required Jump to line 17
What am I doing wrong?
In your path parameter, change
schema:
type: integer
format: int32
to
type: integer
format: int32
In OpenAPI/Swagger 2.0, path, header, query and formData parameters use type directly, without a schema. The schema keyword is used for body parameters only.

Resources