Is this a legal path in an OpenAPI 3.0 yaml spec?
paths:
/config/copy:
get:
...
I have seen that this is not permitted with 2.0, but have found no info on 3.0.
So far I have only seen this when including parameters:
paths:
/user/{id}/posts/{id}:
get:
...
Of course. From the specification:
paths:
/ping:
...
/users:
...
/users/{id}:
another example
paths:
/users:
get:
parameters:
Reference:
https://swagger.io/docs/specification/paths-and-operations/
Related
I am using Swagger 2.0.
Facing the error on UI as:
{"messages":["attribute responses.responses.bad$ref is not of type object"],"schemaValidationMessages":[{"level":"error","domain":"validation","keyword":"oneOf","message":"instance failed to match exactly one schema (matched 0 out of 2)","schema":{"loadingURI":"http://swagger.io/v2/schema.json#","pointer":"/definitions/parameter"},"instance":{"pointer":"/parameters/bad$ref"}}]}
It's a YAML based documentation with the following file referencing in the main swagger.yaml.
swagger: '2.0'
info:
$ref: ./info/index.yaml
host: example.net
basePath: /api/v1
tags:
- name: Name
description: description
schemes:
- http
- https
produces:
- application/json
consumes:
- application/json
parameters:
$ref: ./parameters/index.yaml
responses:
$ref: ./responses/index.yaml
paths:
$ref: ./paths/index.yaml
definitions:
$ref: ./definitions/index.yaml
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
Folder structure:
The parameters/index.yaml and responses/index.xml files are empty. This works perfectly in the Swagger Editor.
I am struggling to find a way to configure the BASE_PATH.
I want to configure the base path server side
I am using open-api-generator to generate subs from a swagger endpoint (asp core web api)
Is there a way to configure different BASE_PATH.
How you define the base URL is specific to the version of OpenAPI Specification you target.
Swagger/OpenAPI 2.0
Define a host at the root of your document. For example:
swagger: "2.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
host: petstore.swagger.io
basePath: /v1
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/pets:
…
OpenAPI 3.x
Define a URL in servers at the root of your document. For example:
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
…
I have a collection of microservices, each with their own complete OpenAPI spec and a root level path
Microservice Definition
openapi: 3.0.0
info:
description: Microservice API
version: '0.0.1'
paths:
/:
get:
tags:
- Root
summary: Root Path
operationId: Root
responses:
'200':
description: Request was successful
deprecated: false
/healthcheck/ping:
get:
tags:
- Healthcheck
summary: Test the reachability of the microservice.
operationId: Ping
responses:
'200':
description: Request was successful
deprecated: false
And a root OpenAPI definition
openapi: "3.0.0"
info:
version: 1.0.0
title: API
servers:
- url: http://api.something.com/v1
paths:
/microservice1:
$ref: "https://storagebucket.someservice.com/service-definitions/microservice-swagger.yaml"
It's been my assumption that it's possible to arrange things this way but I'm getting a whole host of errors in the swagger editor for validity.
Using microservice-swagger.yaml#/paths/~1 gets me somewhere but I would expect that all the paths in the service yaml to simply be appended to the path in the main definition. Does anyone know how to achieve this?
(The reason behind it being to apply this root swagger to an API Gateway whilst maintaining each service as a self contained unit)
I would for example expect the resulting swagger to offer this as a path
/microservice1/healthcheck/ping
I have a following swagger file (parses fine with the Swagger online editor):
swagger: '2.0'
info:
title: Sample
version: 1.1.0
basePath: /base
paths:
/sample:
get:
summary: Gets the samples
parameters:
- $ref: '#parameters/reusableParam'
responses:
200:
description: Success
parameters:
reusableParam:
in: header
name: sample-param
required: true
type: string
description: Sample reusable parameter
When I run code generator on it:
java -jar swagger-codegen-cli-2.2.1.jar generate -i swagger.yaml -l java
It fails with an error:
Exception in thread "main" java.lang.NullPointerException
at io.swagger.codegen.DefaultGenerator.generateParameterId(DefaultGenerator.java:803)
at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:727)
at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:688)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:376)
at io.swagger.codegen.cmd.Generate.run(Generate.java:223)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:36)
Am I doing something wrong in the definition of the reusable parameter?
There's a typo in your spec:
- $ref: '#parameters/reusableParam'
should be
- $ref: '#/parameters/reusableParam'
README.md on https://github.com/swagger-api/swagger-node says 'Kick the tires. Your API is live while you edit (Did we mention no code?)' -> 'Quit faking' on the next step.
So I was under impression that Swagger will generate a fake API for me.
However, if I use such swagger.yaml:
swagger: '2.0'
info:
title: test
description: test
version: "1.0.0"
host: localhost:10010
schemes:
- https
basePath: /api
produces:
- application/json
- text/event-stream
consumes:
- application/json
paths:
/pages:
get:
summary: test
description: test
responses:
200:
description: pages
schema:
type: array
items:
$ref: '#/definitions/Page'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
(where definitions are also given in config)
I receive 404 in both curl http://localhost:10010/api/pages and swagger editor (swagger project edit). I know about x-swagger-router-controller thing but I expected it to work out of the box. Am I doing something wrong?
I should've read the docs more carefully. Swagger gives us the mock mode (swagger project start -m)