Skip to content

Commit

Permalink
feat: support OAS v3.1.0
Browse files Browse the repository at this point in the history
Bump dependency `swagger-ui-react` to v5.0.0
which includes support for OpenAPI Specification (OAS) v3.1.0.

`@types/swagger-ui-react` v4.18.0 seems still compatible.

Closes: backstage#8090
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
  • Loading branch information
pjungermann committed Jun 12, 2023
1 parent 5b38139 commit af748a1
Show file tree
Hide file tree
Showing 9 changed files with 1,170 additions and 413 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-cougars-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/catalog-model': patch
---

Add OpenAPI Specification (OAS) v3.1.0 examples.
5 changes: 5 additions & 0 deletions .changeset/silly-coats-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-api-docs': patch
---

Add support for OpenAPI Specification (OAS) v3.1.0 using swagger-ui v5.0.0.
1 change: 1 addition & 0 deletions packages/catalog-model/examples/all-apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ spec:
- ./apis/hello-world-api.yaml
- ./apis/hello-world-trpc-api.yaml
- ./apis/petstore-api.yaml
- ./apis/petstore-webhook-api.yaml
- ./apis/spotify-api.yaml
- ./apis/streetlights-api.yaml
- ./apis/swapi-graphql.yaml
Expand Down
116 changes: 3 additions & 113 deletions packages/catalog-model/examples/apis/petstore-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,122 +10,12 @@ metadata:
- url: https://github.com/swagger-api/swagger-petstore
title: GitHub Repo
icon: github
- url: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml
- url: https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml
title: API Spec
icon: code
spec:
type: openapi
lifecycle: experimental
owner: team-c
definition: |
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
definition:
$text: ./petstore.oas.yaml
21 changes: 21 additions & 0 deletions packages/catalog-model/examples/apis/petstore-webhook-api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: petstore-webhook
description: The petstore webhook API
tags:
- store
- rest
links:
- url: https://github.com/swagger-api/swagger-petstore
title: GitHub Repo
icon: github
- url: https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.1/webhook-example.yaml
title: API Spec
icon: code
spec:
type: openapi
lifecycle: experimental
owner: team-c
definition:
$text: ./petstore-webhook.oas.yaml
34 changes: 34 additions & 0 deletions packages/catalog-model/examples/apis/petstore-webhook.oas.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
openapi: 3.1.0
info:
title: Webhook Example
version: 1.0.0
# Since OAS 3.1.0 the paths element isn't necessary. Now a valid OpenAPI Document can describe only paths, webhooks, or even only reusable components
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Return a 200 status to indicate that the data was received successfully

components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Loading

0 comments on commit af748a1

Please sign in to comment.