Skip to content

Commit

Permalink
feat(playground): add api.doc.json default tab
Browse files Browse the repository at this point in the history
  • Loading branch information
astahmer committed Jan 16, 2023
1 parent 9f633cc commit 75edaf1
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 0 deletions.
165 changes: 165 additions & 0 deletions examples/petstore-minimal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"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"
}
}
}
}
}
}
1 change: 1 addition & 0 deletions playground/src/Playground/Playground.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const initialInputList = [
index: 2,
preset: "prettier",
},
{ name: "api.doc.json", content: presets.defaultInputJson, index: 3, preset: "petstore.json" },
] as const; // TODO as FileTabData[] with ts 4.9 satisfies
const initialOuputTab = "api.client.ts";

Expand Down
9 changes: 9 additions & 0 deletions playground/src/Playground/PlaygroundWithMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export const PlaygroundWithMachine = () => {
index: 2,
preset: "prettier",
},
{
name: "api.doc.json",
content:
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
(getDecompressedStringFromUrl("doc-json") ?? "") ||
JSON.stringify(initialCtx.inputList[3].content, null, 4),
index: 3,
preset: "petstore.json",
},
];
}

Expand Down
2 changes: 2 additions & 0 deletions playground/src/Playground/presets.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { default as petstoreYaml } from "../../../examples/petstore.yaml?raw";
import { default as petstoreJson } from "../../../examples/petstore-minimal.json?raw";
import { default as defaultOutputTemplate } from "../../../lib/src/templates/default.hbs?raw";

export const presets = {
defaultTemplate: defaultOutputTemplate,
defaultInput: petstoreYaml,
defaultInputJson: petstoreJson,
defaultPrettierConfig: {
printWidth: 120,
tabWidth: 4,
Expand Down

0 comments on commit 75edaf1

Please sign in to comment.