Skip to content

Commit

Permalink
Reproduction #6937 (#6960)
Browse files Browse the repository at this point in the history
* Reproduction #6937

* Add snapshots
  • Loading branch information
ardatan committed May 13, 2024
1 parent 5bfef52 commit 7b30b82
Show file tree
Hide file tree
Showing 3 changed files with 230 additions and 0 deletions.
69 changes: 69 additions & 0 deletions packages/loaders/openapi/tests/__snapshots__/schemas.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47261,6 +47261,75 @@ enum HTTPMethod {
}"
`;

exports[`Schemas DefaultValues should generate the correct schema: DefaultValues 1`] = `
"schema @transport(subgraph: "DefaultValues", kind: "rest") {
query: Query
mutation: Mutation
}

directive @httpOperation(subgraph: String, path: String, operationSpecificHeaders: ObjMap, httpMethod: HTTPMethod, isBinary: Boolean, requestBaseBody: ObjMap, queryParamArgMap: ObjMap, queryStringOptionsByParam: ObjMap, jsonApiFields: Boolean) on FIELD_DEFINITION

directive @transport(subgraph: String, kind: String, location: String, headers: ObjMap, queryStringOptions: ObjMap, queryParams: ObjMap) on OBJECT

type Query {
Retrieve_list_of_stacks: StacksResponse @httpOperation(subgraph: "DefaultValues", path: "/stacks", httpMethod: GET)
}

type StacksResponse {
data: [Stack]!
}

type Stack {
"""Stack name"""
name: String!
"""Stack description"""
description: String!
"""list of items in the stack"""
items: [StackItem]!
}

type StackItem {
item: JSON!
}

"""
The \`JSON\` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
"""
scalar JSON @specifiedBy(url: "http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf")

type Mutation {
"""Creates a new stack"""
Create_a_stack(input: CreateStackPayload_Input!): JSON @httpOperation(subgraph: "DefaultValues", path: "/stacks", httpMethod: POST)
}

input CreateStackPayload_Input {
"""Stack name"""
name: String!
"""Stack description"""
description: String!
"""Stack Items"""
items: [StackItem_Input]!
}

input StackItem_Input {
item: JSON! = {}
}

scalar ObjMap

enum HTTPMethod {
GET
HEAD
POST
PUT
DELETE
CONNECT
OPTIONS
TRACE
PATCH
}"
`;

exports[`Schemas Dictionary should generate the correct schema: Dictionary 1`] = `
"schema @transport(subgraph: "Dictionary", kind: "rest", location: "http://localhost:{args.port:3002}/{args.basePath:api}") {
query: Query
Expand Down
160 changes: 160 additions & 0 deletions packages/loaders/openapi/tests/fixtures/default-values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
{
"swagger": "2.0",
"basePath": "/api/v1",
"paths": {
"/stacks": {
"get": {
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/StacksResponse"
}
},
"401": {
"description": "Unauthorized"
}
},
"operationId": "Retrieve list of stacks",
"security": [
{
"jwt": []
}
],
"tags": ["Stacks"]
},
"post": {
"responses": {
"201": {
"description": "Created"
},
"400": {
"description": "Bad request"
},
"401": {
"description": "Unauthorized"
}
},
"description": "Creates a new stack",
"operationId": "Create a stack",
"parameters": [
{
"name": "payload",
"required": true,
"in": "body",
"schema": {
"$ref": "#/definitions/CreateStackPayload"
}
}
],
"security": [
{
"jwt": []
}
],
"tags": ["Stacks"]
}
}
},
"info": {
"title": "My Stacks API",
"version": "1.0",
"description": "Manage your stacks"
},
"produces": ["application/json"],
"consumes": ["application/json"],
"securityDefinitions": {
"jwt": {
"type": "apiKey",
"in": "header",
"name": "Authorization"
}
},
"security": [
{
"jwt": []
}
],
"tags": [
{
"name": "Stacks"
}
],
"definitions": {
"StacksResponse": {
"required": ["data"],
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Stack"
}
}
}
},
"Stack": {
"required": ["name", "description", "items"],
"properties": {
"name": {
"type": "string",
"description": "Stack name"
},
"description": {
"type": "string",
"description": "Stack description"
},
"items": {
"type": "array",
"description": "list of items in the stack",
"items": {
"$ref": "#/definitions/StackItem"
}
}
},
"type": "object",
"additionalProperties": false
},
"CreateStackPayload": {
"required": ["name", "description", "items"],
"properties": {
"name": {
"type": "string",
"description": "Stack name"
},
"description": {
"type": "string",
"description": "Stack description"
},
"items": {
"type": "array",
"description": "Stack Items",
"items": {
"$ref": "#/definitions/StackItem"
}
}
},
"type": "object",
"additionalProperties": false
},
"StackItem": {
"required": ["item"],
"properties": {
"item": {
"type": "object",
"description": "Item details",
"default": {}
}
},
"type": "object",
"additionalProperties": false
}
},
"responses": {
"ParseError": {
"description": "When a mask can't be parsed"
},
"MaskError": {
"description": "When any error occurs on mask"
}
}
}
1 change: 1 addition & 0 deletions packages/loaders/openapi/tests/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const schemas: Record<string, string> = {
StackExchange:
'https://raw.githubusercontent.com/grokify/api-specs/master/stackexchange/stackexchange-api-v2.2_openapi-v3.0.yaml',
YouTrack: 'youtrack.json',
DefaultValues: 'default-values.json',
};

describe('Schemas', () => {
Expand Down

0 comments on commit 7b30b82

Please sign in to comment.