Skip to content

Commit

Permalink
chore(openapi): reproduction #1970
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Mar 31, 2023
1 parent cc754db commit 7a2d597
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/loaders/openapi/tests/__snapshots__/schemas.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41864,6 +41864,71 @@ enum HTTPMethod {
}"
`;

exports[`Schemas Different fields with the same type should generate the correct schema: Different fields with the same type 1`] = `
"schema {
query: Query
}

directive @enum(value: String) on ENUM_VALUE

directive @resolveRoot on FIELD_DEFINITION

directive @globalOptions(sourceName: String, endpoint: String, operationHeaders: ObjMap, queryStringOptions: ObjMap, queryParams: ObjMap) on OBJECT

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

type Query @globalOptions(sourceName: "Different fields with the same type", endpoint: "https://dev.url.com/api/v5") {
"## Behavior"
get_approval_request_v5: Approval_Request___Get @httpOperation(path: "/get-approval-request", operationSpecificHeaders: "{\\"accept\\":\\"application/json\\"}", httpMethod: GET)
}

type Approval_Request___Get {
id: String!
type: Approval_Request_Type!
type2: Approval_Request_Type!
submissionTimestamp: DateTime!
JSON: JSON @resolveRoot
}

enum Approval_Request_Type {
V4_SHIFT_OPEN
V4_SHIFT_OFFER
V4_SHIFT_CANCEL
V4_SHIFT_TRADE
V4_AVAILABILITY_TIME_OFF
V5_TIME_OFF
V5_AVAILABILITY
V5_OPEN_SHIFT
V5_SHIFT_DIRECT_OFFER
V5_DIRECT_SWAP
V5_DIRECT_RELEASE
V5_POOL_RELEASE
V5_POOL_SWAP
V5_POOL_DUAL
V5_BATCH_PUNCH_EDIT
}

"A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the \`date-time\` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar."
scalar DateTime

"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")

scalar ObjMap

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

exports[`Schemas GitHub should generate the correct schema: GitHub 1`] = `
"schema {
query: Query
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
openapi: 3.0.0
info:
version: '2021.04'
title: Some title
description: |-
## Some description
x-codegen-values:
apiVersionString: v5
apiVersionInt: 5
filePath: test.yaml
servers:
- url: https://dev.url.com/api/v5
description: The dev API server
paths:
'/get-approval-request':
parameters:
- name: employeeId
in: path
required: true
schema:
type: string
- name: approvalRequestId
in: path
required: true
schema:
type: string
get:
operationId: get-approval-request-v5
summary: Get Approval Request
description: |-
## Behavior
tags:
- Approval Requests
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/v5_approvalRequest_approvalRequestGet'
components:
schemas:
v5_approvalRequest_approvalRequestGet:
title: Approval Request - Get
allOf:
- $ref: '#/components/schemas/v5_approvalRequest_approvalRequestBase'
- type: object
# properties:
# someThing:
# type: object
# oneOf:
# - $ref: "...""
v5_approvalRequest_approvalRequestBase:
title: Approval Request - Base
allOf:
- $ref: '#/components/schemas/v5_approvalRequest_approvalRequestSummaryGet'
- type: object
# properties:
# someOtherThing:
# type: object
# oneOf:
# - $ref: "...""
v5_approvalRequest_approvalRequestSummaryGet:
title: Approval Request Summary - Get
type: object
properties:
id:
type: string
type:
$ref: '#/components/schemas/v5_approvalRequest_approvalRequestType'
type2:
$ref: '#/components/schemas/v5_approvalRequest_approvalRequestType'
submissionTimestamp:
type: string
format: date-time
required:
- id
- type
- type2
- submissionTimestamp
v5_approvalRequest_approvalRequestType:
title: Approval Request Type
type: string
enum:
- V4_SHIFT_OPEN
- V4_SHIFT_OFFER
- V4_SHIFT_CANCEL
- V4_SHIFT_TRADE
- V4_AVAILABILITY_TIME_OFF
- V5_TIME_OFF
- V5_AVAILABILITY
- V5_OPEN_SHIFT
- V5_SHIFT_DIRECT_OFFER
- V5_DIRECT_SWAP
- V5_DIRECT_RELEASE
- V5_POOL_RELEASE
- V5_POOL_SWAP
- V5_POOL_DUAL
- V5_BATCH_PUNCH_EDIT
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 @@ -21,6 +21,7 @@ const schemas: Record<string, string> = {
MeiliSearch: 'meilisearch.yml',
BlockFrost: 'blockfrost.json',
'Int64 with Defaults': 'int64-with-defaults.yml',
'Different fields with the same type': 'different-prop-same-type.yaml',
};

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

0 comments on commit 7a2d597

Please sign in to comment.