diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts index f28842907e..57654e4e49 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts @@ -854,3 +854,389 @@ export const ModelWithPatternWritableSchema = { } } } as const; + +export const CallWithDescriptionsQuerySchema = { + properties: { + parameterWithBreaks: { + description: 'Testing multiline comments in string: First line\nSecond line\n\nFourth line', + type: 'string' + }, + parameterWithBackticks: { + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work', + type: 'string' + }, + parameterWithSlashes: { + description: 'Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work', + type: 'string' + }, + parameterWithExpressionPlaceholders: { + description: 'Testing expression placeholders in string: ${expression} should work', + type: 'string' + }, + parameterWithQuotes: { + description: 'Testing quotes in string: \'single quote\'\'\' and "double quotes""" should work', + type: 'string' + }, + parameterWithReservedCharacters: { + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work', + type: 'string' + } + }, + type: 'object' +} as const; + +export const CallWithParametersHeadersSchema = { + properties: { + parameterHeader: { + description: 'This is the parameter that goes into the header', + type: 'string' + } + }, + required: [ + 'parameterHeader' + ], + type: 'object' +} as const; + +export const CallWithParametersPathSchema = { + properties: { + parameterPath: { + description: 'This is the parameter that goes into the path', + type: 'string' + }, + 'api-version': { + description: 'api-version should be required in standalone clients', + type: 'string' + } + }, + required: [ + 'parameterPath', + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithParametersQuerySchema = { + properties: { + parameterQuery: { + description: 'This is the parameter that goes into the query params', + type: 'string' + } + }, + required: [ + 'parameterQuery' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesHeadersSchema = { + properties: { + 'parameter.header': { + description: 'This is the parameter that goes into the request header', + type: 'string' + } + }, + required: [ + 'parameter.header' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesPathSchema = { + properties: { + 'parameter.path.1': { + description: 'This is the parameter that goes into the path', + type: 'string' + }, + 'parameter-path-2': { + description: 'This is the parameter that goes into the path', + type: 'string' + }, + 'PARAMETER-PATH-3': { + description: 'This is the parameter that goes into the path', + type: 'string' + }, + 'api-version': { + description: 'api-version should be required in standalone clients', + type: 'string' + } + }, + required: [ + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesQuerySchema = { + properties: { + default: { + description: 'This is the parameter with a reserved keyword', + type: 'string' + }, + 'parameter-query': { + description: 'This is the parameter that goes into the request query params', + type: 'string' + } + }, + required: [ + 'parameter-query' + ], + type: 'object' +} as const; + +export const CallWithDefaultParametersQuerySchema = { + properties: { + parameterString: { + description: 'This is a simple string with default value', + default: 'Hello World!', + type: 'string' + }, + parameterNumber: { + description: 'This is a simple number with default value', + default: 123, + type: 'number' + }, + parameterBoolean: { + description: 'This is a simple boolean with default value', + default: true, + type: 'boolean' + } + }, + required: [ + 'parameterString', + 'parameterNumber', + 'parameterBoolean' + ], + type: 'object' +} as const; + +export const CallWithDefaultOptionalParametersQuerySchema = { + properties: { + parameterString: { + description: 'This is a simple string that is optional with default value', + default: 'Hello World!', + type: 'string' + }, + parameterNumber: { + description: 'This is a simple number that is optional with default value', + default: 123, + type: 'number' + }, + parameterBoolean: { + description: 'This is a simple boolean that is optional with default value', + default: true, + type: 'boolean' + } + }, + type: 'object' +} as const; + +export const CallToTestOrderOfParamsQuerySchema = { + properties: { + parameterOptionalStringWithDefault: { + description: 'This is a optional string with default', + default: 'Hello World!', + type: 'string' + }, + parameterOptionalStringWithEmptyDefault: { + description: 'This is a optional string with empty default', + default: '', + type: 'string' + }, + parameterOptionalStringWithNoDefault: { + description: 'This is a optional string with no default', + type: 'string' + }, + parameterStringWithDefault: { + description: 'This is a string with default', + default: 'Hello World!', + type: 'string' + }, + parameterStringWithEmptyDefault: { + description: 'This is a string with empty default', + default: '', + type: 'string' + }, + parameterStringWithNoDefault: { + description: 'This is a string with no default', + type: 'string' + }, + parameterStringNullableWithNoDefault: { + 'x-nullable': true, + description: 'This is a string that can be null with no default', + type: 'string' + }, + parameterStringNullableWithDefault: { + 'x-nullable': true, + description: 'This is a string that can be null with default', + type: 'string', + default: null + } + }, + required: [ + 'parameterStringWithDefault', + 'parameterStringWithEmptyDefault', + 'parameterStringWithNoDefault' + ], + type: 'object' +} as const; + +export const CollectionFormatQuerySchema = { + properties: { + parameterArrayCSV: { + description: 'This is an array parameter that is sent as csv format (comma-separated values)', + type: 'array', + items: { + type: 'string' + }, + collectionFormat: 'csv' + }, + parameterArraySSV: { + description: 'This is an array parameter that is sent as ssv format (space-separated values)', + type: 'array', + items: { + type: 'string' + }, + collectionFormat: 'ssv' + }, + parameterArrayTSV: { + description: 'This is an array parameter that is sent as tsv format (tab-separated values)', + type: 'array', + items: { + type: 'string' + }, + collectionFormat: 'tsv' + }, + parameterArrayPipes: { + description: 'This is an array parameter that is sent as pipes format (pipe-separated values)', + type: 'array', + items: { + type: 'string' + }, + collectionFormat: 'pipes' + }, + parameterArrayMulti: { + description: 'This is an array parameter that is sent as multi format (multiple parameter instances)', + type: 'array', + items: { + type: 'string' + }, + collectionFormat: 'multi' + } + }, + required: [ + 'parameterArrayCSV', + 'parameterArraySSV', + 'parameterArrayTSV', + 'parameterArrayPipes', + 'parameterArrayMulti' + ], + type: 'object' +} as const; + +export const TypesPathSchema = { + properties: { + id: { + description: 'This is a number parameter', + type: 'integer', + format: 'int32' + } + }, + type: 'object' +} as const; + +export const TypesQuerySchema = { + properties: { + parameterNumber: { + description: 'This is a number parameter', + default: 123, + type: 'number' + }, + parameterString: { + description: 'This is a string parameter', + default: 'default', + type: 'string' + }, + parameterBoolean: { + description: 'This is a boolean parameter', + default: true, + type: 'boolean' + }, + parameterArray: { + description: 'This is an array parameter', + type: 'array', + items: { + type: 'string' + } + }, + parameterDictionary: { + description: 'This is a dictionary parameter', + type: 'object', + items: { + type: 'string' + } + } + }, + required: [ + 'parameterNumber', + 'parameterString', + 'parameterBoolean', + 'parameterArray', + 'parameterDictionary' + ], + type: 'object' +} as const; + +export const ComplexTypesQuerySchema = { + properties: { + parameterObject: { + description: 'Parameter containing object', + type: 'object', + properties: { + first: { + type: 'object', + properties: { + second: { + type: 'object', + properties: { + third: { + type: 'string' + } + } + } + } + } + } + } + }, + required: [ + 'parameterObject' + ], + type: 'object' +} as const; + +export const TestErrorCodeQuerySchema = { + properties: { + status: { + description: 'Status code to return', + type: 'string' + } + }, + required: [ + 'status' + ], + type: 'object' +} as const; + +export const NonAsciiæøåÆøÅöôêÊ字符串QuerySchema = { + properties: { + nonAsciiParamæøåÆØÅöôêÊ: { + description: 'Dummy input param', + type: 'integer' + } + }, + required: [ + 'nonAsciiParamæøåÆØÅöôêÊ' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts new file mode 100644 index 0000000000..f80b43129a --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts @@ -0,0 +1,53 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export const CatSchema = { + type: 'object', + properties: { + id: { + type: 'integer' + }, + name: { + type: 'string' + } + } +} as const; + +export const GetCatsQuerySchema = { + properties: { + is_adopted: { + description: 'Filter by adoption status', + type: 'boolean' + }, + color: { + description: 'Filter by fur color', + type: 'string' + } + }, + type: 'object' +} as const; + +export const GetCatsByCatIdHeadersSchema = { + properties: { + 'x-api-key': { + description: 'API key for authentication', + type: 'string' + } + }, + required: [ + 'x-api-key' + ], + type: 'object' +} as const; + +export const GetCatsByCatIdPathSchema = { + properties: { + cat_id: { + description: 'The ID of the cat', + type: 'integer' + } + }, + required: [ + 'cat_id' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts index 636147d56a..50b7cb58f2 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/default/schemas.gen.ts @@ -2403,3 +2403,630 @@ export const Generic_Schema_Duplicate_Issue_1_System_String_WritableSchema = { }, additionalProperties: false } as const; + +export const GetApiVbyApiVersionSimpleOperationPathSchema = { + properties: { + foo_param: { + type: 'string', + description: 'foo in method' + } + }, + required: [ + 'foo_param' + ], + type: 'object' +} as const; + +export const DeleteFooHeadersSchema = { + properties: { + 'x-Foo-Bar': { + $ref: '#/components/schemas/ModelWithString' + } + }, + required: [ + 'x-Foo-Bar' + ], + type: 'object' +} as const; + +export const DeleteFooPathSchema = { + properties: { + foo_param: { + type: 'string', + description: 'foo in method' + }, + BarParam: { + type: 'string', + description: 'bar in method' + } + }, + required: [ + 'foo_param', + 'BarParam' + ], + type: 'object' +} as const; + +export const CallWithDescriptionsQuerySchema = { + properties: { + parameterWithBreaks: { + type: 'string', + description: 'Testing multiline comments in string: First line\nSecond line\n\nFourth line' + }, + parameterWithBackticks: { + type: 'string', + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work' + }, + parameterWithSlashes: { + type: 'string', + description: 'Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work' + }, + parameterWithExpressionPlaceholders: { + type: 'string', + description: 'Testing expression placeholders in string: ${expression} should work' + }, + parameterWithQuotes: { + type: 'string', + description: 'Testing quotes in string: \'single quote\'\'\' and "double quotes""" should work' + }, + parameterWithReservedCharacters: { + type: 'string', + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work' + } + }, + type: 'object' +} as const; + +export const DeprecatedCallHeadersSchema = { + properties: { + parameter: { + nullable: true, + allOf: [ + { + $ref: '#/components/schemas/DeprecatedModel' + } + ], + description: 'This parameter is deprecated' + } + }, + required: [ + 'parameter' + ], + type: 'object' +} as const; + +export const CallWithParametersCookiesSchema = { + properties: { + parameterCookie: { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the cookie' + } + }, + required: [ + 'parameterCookie' + ], + type: 'object' +} as const; + +export const CallWithParametersHeadersSchema = { + properties: { + parameterHeader: { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the header' + } + }, + required: [ + 'parameterHeader' + ], + type: 'object' +} as const; + +export const CallWithParametersPathSchema = { + properties: { + parameterPath: { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'api-version': { + nullable: true, + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'parameterPath', + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithParametersQuerySchema = { + properties: { + foo_ref_enum: { + $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + }, + foo_all_of_enum: { + allOf: [ + { + $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + ] + }, + cursor: { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the query params' + } + }, + required: [ + 'foo_all_of_enum', + 'cursor' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesCookiesSchema = { + properties: { + 'PARAMETER-COOKIE': { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the cookie' + } + }, + required: [ + 'PARAMETER-COOKIE' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesHeadersSchema = { + properties: { + 'parameter.header': { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the request header' + } + }, + required: [ + 'parameter.header' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesPathSchema = { + properties: { + 'parameter.path.1': { + nullable: false, + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'parameter-path-2': { + nullable: false, + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'PARAMETER-PATH-3': { + nullable: false, + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'api-version': { + nullable: true, + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesQuerySchema = { + properties: { + default: { + nullable: false, + type: 'string', + description: 'This is the parameter with a reserved keyword' + }, + 'parameter-query': { + nullable: true, + type: 'string', + description: 'This is the parameter that goes into the request query params' + } + }, + required: [ + 'parameter-query' + ], + type: 'object' +} as const; + +export const GetCallWithOptionalParamQuerySchema = { + properties: { + page: { + type: 'number', + description: 'This is an optional parameter' + } + }, + type: 'object' +} as const; + +export const PostCallWithOptionalParamQuerySchema = { + properties: { + parameter: { + $ref: '#/components/schemas/Pageable' + } + }, + required: [ + 'parameter' + ], + type: 'object' +} as const; + +export const CallWithDefaultParametersQuerySchema = { + properties: { + parameterString: { + nullable: true, + type: 'string', + default: 'Hello World!', + description: 'This is a simple string with default value' + }, + parameterNumber: { + nullable: true, + type: 'number', + default: 123, + description: 'This is a simple number with default value' + }, + parameterBoolean: { + nullable: true, + type: 'boolean', + default: true, + description: 'This is a simple boolean with default value' + }, + parameterEnum: { + enum: [ + 'Success', + 'Warning', + 'Error' + ], + default: 0, + description: 'This is a simple enum with default value' + }, + parameterModel: { + nullable: true, + allOf: [ + { + $ref: '#/components/schemas/ModelWithString' + } + ], + default: { + prop: 'Hello World!' + }, + description: 'This is a simple model with default value' + } + }, + type: 'object' +} as const; + +export const CallWithDefaultOptionalParametersQuerySchema = { + properties: { + parameterString: { + type: 'string', + default: 'Hello World!', + description: 'This is a simple string that is optional with default value' + }, + parameterNumber: { + type: 'number', + default: 123, + description: 'This is a simple number that is optional with default value' + }, + parameterBoolean: { + type: 'boolean', + default: true, + description: 'This is a simple boolean that is optional with default value' + }, + parameterEnum: { + enum: [ + 'Success', + 'Warning', + 'Error' + ], + default: 0, + description: 'This is a simple enum that is optional with default value' + }, + parameterModel: { + $ref: '#/components/schemas/ModelWithString', + default: { + prop: 'Hello World!' + } + } + }, + type: 'object' +} as const; + +export const CallToTestOrderOfParamsQuerySchema = { + properties: { + parameterOptionalStringWithDefault: { + type: 'string', + default: 'Hello World!', + description: 'This is a optional string with default' + }, + parameterOptionalStringWithEmptyDefault: { + type: 'string', + default: '', + description: 'This is a optional string with empty default' + }, + parameterOptionalStringWithNoDefault: { + type: 'string', + description: 'This is a optional string with no default' + }, + parameterStringWithDefault: { + type: 'string', + default: 'Hello World!', + description: 'This is a string with default' + }, + parameterStringWithEmptyDefault: { + type: 'string', + default: '', + description: 'This is a string with empty default' + }, + parameterStringWithNoDefault: { + type: 'string', + description: 'This is a string with no default' + }, + parameterStringNullableWithNoDefault: { + type: 'string', + nullable: true, + description: 'This is a string that can be null with no default' + }, + parameterStringNullableWithDefault: { + type: 'string', + nullable: true, + default: null, + description: 'This is a string that can be null with default' + } + }, + required: [ + 'parameterStringWithDefault', + 'parameterStringWithEmptyDefault', + 'parameterStringWithNoDefault' + ], + type: 'object' +} as const; + +export const CollectionFormatQuerySchema = { + properties: { + parameterArrayCSV: { + nullable: true, + type: 'array', + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as csv format (comma-separated values)' + }, + parameterArraySSV: { + nullable: true, + type: 'array', + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as ssv format (space-separated values)' + }, + parameterArrayTSV: { + nullable: true, + type: 'array', + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as tsv format (tab-separated values)' + }, + parameterArrayPipes: { + nullable: true, + type: 'array', + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as pipes format (pipe-separated values)' + }, + parameterArrayMulti: { + nullable: true, + type: 'array', + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as multi format (multiple parameter instances)' + } + }, + required: [ + 'parameterArrayCSV', + 'parameterArraySSV', + 'parameterArrayTSV', + 'parameterArrayPipes', + 'parameterArrayMulti' + ], + type: 'object' +} as const; + +export const TypesPathSchema = { + properties: { + id: { + type: 'integer', + format: 'int32', + description: 'This is a number parameter' + } + }, + type: 'object' +} as const; + +export const TypesQuerySchema = { + properties: { + parameterNumber: { + type: 'number', + default: 123, + description: 'This is a number parameter' + }, + parameterString: { + type: 'string', + default: 'default', + nullable: true, + description: 'This is a string parameter' + }, + parameterBoolean: { + type: 'boolean', + default: true, + nullable: true, + description: 'This is a boolean parameter' + }, + parameterObject: { + type: 'object', + default: null, + nullable: true, + description: 'This is an object parameter' + }, + parameterArray: { + type: 'array', + items: { + type: 'string' + }, + nullable: true, + description: 'This is an array parameter' + }, + parameterDictionary: { + type: 'object', + items: { + type: 'string' + }, + nullable: true, + description: 'This is a dictionary parameter' + }, + parameterEnum: { + enum: [ + 'Success', + 'Warning', + 'Error' + ], + nullable: true, + description: 'This is an enum parameter' + } + }, + required: [ + 'parameterNumber', + 'parameterString', + 'parameterBoolean', + 'parameterObject', + 'parameterArray', + 'parameterDictionary', + 'parameterEnum' + ], + type: 'object' +} as const; + +export const UploadFilePathSchema = { + properties: { + 'api-version': { + type: 'string', + nullable: true, + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'api-version' + ], + type: 'object' +} as const; + +export const FileResponsePathSchema = { + properties: { + id: { + type: 'string' + }, + 'api-version': { + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'id', + 'api-version' + ], + type: 'object' +} as const; + +export const ComplexTypesQuerySchema = { + properties: { + parameterObject: { + type: 'object', + properties: { + first: { + type: 'object', + properties: { + second: { + type: 'object', + properties: { + third: { + type: 'string' + } + } + } + } + } + }, + description: 'Parameter containing object' + }, + parameterReference: { + $ref: '#/components/schemas/ModelWithString' + } + }, + required: [ + 'parameterObject', + 'parameterReference' + ], + type: 'object' +} as const; + +export const ComplexParamsPathSchema = { + properties: { + id: { + type: 'integer', + format: 'int32' + }, + 'api-version': { + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'id', + 'api-version' + ], + type: 'object' +} as const; + +export const TestErrorCodeQuerySchema = { + properties: { + status: { + type: 'integer', + description: 'Status code to return' + } + }, + required: [ + 'status' + ], + type: 'object' +} as const; + +export const NonAsciiæøåÆøÅöôêÊ字符串QuerySchema = { + properties: { + nonAsciiParamæøåÆØÅöôêÊ: { + type: 'integer', + description: 'Dummy input param' + } + }, + required: [ + 'nonAsciiParamæøåÆØÅöôêÊ' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts new file mode 100644 index 0000000000..ba227aeb53 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts @@ -0,0 +1,68 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export const CatSchema = { + type: 'object', + properties: { + id: { + type: 'integer' + }, + name: { + type: 'string' + } + } +} as const; + +export const GetCatsQuerySchema = { + properties: { + is_adopted: { + type: 'boolean', + description: 'Filter by adoption status' + }, + color: { + type: 'string', + description: 'Filter by fur color' + }, + vaccination: { + type: 'object', + additionalProperties: false, + required: [ + 'vaccine_name' + ], + properties: { + vaccine_name: { + type: 'string' + }, + dose_count: { + type: 'number' + } + } + } + }, + type: 'object' +} as const; + +export const GetCatsByCatIdHeadersSchema = { + properties: { + 'x-api-key': { + type: 'string', + description: 'API key for authentication' + } + }, + required: [ + 'x-api-key' + ], + type: 'object' +} as const; + +export const GetCatsByCatIdPathSchema = { + properties: { + cat_id: { + type: 'integer', + description: 'The ID of the cat' + } + }, + required: [ + 'cat_id' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/default/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/default/schemas.gen.ts index 0c05f072f1..bf5665a297 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/default/schemas.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/default/schemas.gen.ts @@ -2458,3 +2458,697 @@ export const Generic_Schema_Duplicate_Issue_1_System_String_WritableSchema = { }, additionalProperties: false } as const; + +export const GetApiVbyApiVersionSimpleOperationPathSchema = { + properties: { + foo_param: { + oneOf: [ + { + type: 'string' + }, + { + format: 'uuid', + type: 'string' + } + ], + description: 'foo in method' + } + }, + required: [ + 'foo_param' + ], + type: 'object' +} as const; + +export const DeleteFooHeadersSchema = { + properties: { + 'x-Foo-Bar': { + $ref: '#/components/schemas/ModelWithString' + } + }, + required: [ + 'x-Foo-Bar' + ], + type: 'object' +} as const; + +export const DeleteFooPathSchema = { + properties: { + foo_param: { + type: 'string', + description: 'foo in method' + }, + BarParam: { + type: 'string', + description: 'bar in method' + } + }, + required: [ + 'foo_param', + 'BarParam' + ], + type: 'object' +} as const; + +export const CallWithDescriptionsQuerySchema = { + properties: { + parameterWithBreaks: { + type: 'string', + description: 'Testing multiline comments in string: First line\nSecond line\n\nFourth line' + }, + parameterWithBackticks: { + type: 'string', + description: 'Testing backticks in string: `backticks` and ```multiple backticks``` should work' + }, + parameterWithSlashes: { + type: 'string', + description: 'Testing slashes in string: \\backwards\\\\\\ and /forwards/// should work' + }, + parameterWithExpressionPlaceholders: { + type: 'string', + description: 'Testing expression placeholders in string: ${expression} should work' + }, + parameterWithQuotes: { + type: 'string', + description: 'Testing quotes in string: \'single quote\'\'\' and "double quotes""" should work' + }, + parameterWithReservedCharacters: { + type: 'string', + description: 'Testing reserved characters in string: /* inline */ and /** inline **/ should work' + } + }, + type: 'object' +} as const; + +export const DeprecatedCallHeadersSchema = { + properties: { + parameter: { + oneOf: [ + { + $ref: '#/components/schemas/DeprecatedModel' + }, + { + type: 'null' + } + ], + description: 'This parameter is deprecated' + } + }, + required: [ + 'parameter' + ], + type: 'object' +} as const; + +export const CallWithParametersCookiesSchema = { + properties: { + parameterCookie: { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the cookie' + } + }, + required: [ + 'parameterCookie' + ], + type: 'object' +} as const; + +export const CallWithParametersHeadersSchema = { + properties: { + parameterHeader: { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the header' + } + }, + required: [ + 'parameterHeader' + ], + type: 'object' +} as const; + +export const CallWithParametersPathSchema = { + properties: { + parameterPath: { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the path' + }, + 'api-version': { + type: [ + 'string', + 'null' + ], + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'parameterPath', + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithParametersQuerySchema = { + properties: { + foo_ref_enum: { + $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + }, + foo_all_of_enum: { + allOf: [ + { + $ref: '#/components/schemas/ModelWithNestedArrayEnumsDataFoo' + } + ] + }, + cursor: { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the query params' + } + }, + required: [ + 'foo_all_of_enum', + 'cursor' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesCookiesSchema = { + properties: { + 'PARAMETER-COOKIE': { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the cookie' + } + }, + required: [ + 'PARAMETER-COOKIE' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesHeadersSchema = { + properties: { + 'parameter.header': { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the request header' + } + }, + required: [ + 'parameter.header' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesPathSchema = { + properties: { + 'parameter.path.1': { + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'parameter-path-2': { + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'PARAMETER-PATH-3': { + type: 'string', + description: 'This is the parameter that goes into the path' + }, + 'api-version': { + type: [ + 'string', + 'null' + ], + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'api-version' + ], + type: 'object' +} as const; + +export const CallWithWeirdParameterNamesQuerySchema = { + properties: { + default: { + type: 'string', + description: 'This is the parameter with a reserved keyword' + }, + 'parameter-query': { + type: [ + 'string', + 'null' + ], + description: 'This is the parameter that goes into the request query params' + } + }, + required: [ + 'parameter-query' + ], + type: 'object' +} as const; + +export const GetCallWithOptionalParamQuerySchema = { + properties: { + page: { + type: 'number', + description: 'This is an optional parameter' + } + }, + type: 'object' +} as const; + +export const PostCallWithOptionalParamQuerySchema = { + properties: { + parameter: { + $ref: '#/components/schemas/Pageable', + description: 'This is a required parameter' + } + }, + required: [ + 'parameter' + ], + type: 'object' +} as const; + +export const CallWithDefaultParametersQuerySchema = { + properties: { + parameterString: { + default: 'Hello World!', + type: [ + 'string', + 'null' + ], + description: 'This is a simple string with default value' + }, + parameterNumber: { + default: 123, + type: [ + 'number', + 'null' + ], + description: 'This is a simple number with default value' + }, + parameterBoolean: { + default: true, + type: [ + 'boolean', + 'null' + ], + description: 'This is a simple boolean with default value' + }, + parameterEnum: { + enum: [ + 'Success', + 'Warning', + 'Error' + ], + default: 0, + description: 'This is a simple enum with default value' + }, + parameterModel: { + oneOf: [ + { + $ref: '#/components/schemas/ModelWithString', + default: { + prop: 'Hello World!' + } + }, + { + type: 'null' + } + ], + description: 'This is a simple model with default value' + } + }, + type: 'object' +} as const; + +export const CallWithDefaultOptionalParametersQuerySchema = { + properties: { + parameterString: { + type: 'string', + default: 'Hello World!', + description: 'This is a simple string that is optional with default value' + }, + parameterNumber: { + type: 'number', + default: 123, + description: 'This is a simple number that is optional with default value' + }, + parameterBoolean: { + type: 'boolean', + default: true, + description: 'This is a simple boolean that is optional with default value' + }, + parameterEnum: { + enum: [ + 'Success', + 'Warning', + 'Error' + ], + default: 0, + description: 'This is a simple enum that is optional with default value' + }, + parameterModel: { + $ref: '#/components/schemas/ModelWithString', + default: { + prop: 'Hello World!' + }, + description: 'This is a simple model that is optional with default value' + } + }, + type: 'object' +} as const; + +export const CallToTestOrderOfParamsQuerySchema = { + properties: { + parameterOptionalStringWithDefault: { + type: 'string', + default: 'Hello World!', + description: 'This is a optional string with default' + }, + parameterOptionalStringWithEmptyDefault: { + type: 'string', + default: '', + description: 'This is a optional string with empty default' + }, + parameterOptionalStringWithNoDefault: { + type: 'string', + description: 'This is a optional string with no default' + }, + parameterStringWithDefault: { + type: 'string', + default: 'Hello World!', + description: 'This is a string with default' + }, + parameterStringWithEmptyDefault: { + type: 'string', + default: '', + description: 'This is a string with empty default' + }, + parameterStringWithNoDefault: { + type: 'string', + description: 'This is a string with no default' + }, + parameterStringNullableWithNoDefault: { + type: [ + 'string', + 'null' + ], + description: 'This is a string that can be null with no default' + }, + parameterStringNullableWithDefault: { + default: null, + type: [ + 'string', + 'null' + ], + description: 'This is a string that can be null with default' + } + }, + required: [ + 'parameterStringWithDefault', + 'parameterStringWithEmptyDefault', + 'parameterStringWithNoDefault' + ], + type: 'object' +} as const; + +export const CollectionFormatQuerySchema = { + properties: { + parameterArrayCSV: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as csv format (comma-separated values)' + }, + parameterArraySSV: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as ssv format (space-separated values)' + }, + parameterArrayTSV: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as tsv format (tab-separated values)' + }, + parameterArrayPipes: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as pipes format (pipe-separated values)' + }, + parameterArrayMulti: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter that is sent as multi format (multiple parameter instances)' + } + }, + required: [ + 'parameterArrayCSV', + 'parameterArraySSV', + 'parameterArrayTSV', + 'parameterArrayPipes', + 'parameterArrayMulti' + ], + type: 'object' +} as const; + +export const TypesPathSchema = { + properties: { + id: { + type: 'integer', + format: 'int32', + description: 'This is a number parameter' + } + }, + type: 'object' +} as const; + +export const TypesQuerySchema = { + properties: { + parameterNumber: { + type: 'number', + default: 123, + description: 'This is a number parameter' + }, + parameterString: { + type: [ + 'string', + 'null' + ], + default: 'default', + description: 'This is a string parameter' + }, + parameterBoolean: { + type: [ + 'boolean', + 'null' + ], + default: true, + description: 'This is a boolean parameter' + }, + parameterObject: { + type: [ + 'object', + 'null' + ], + default: null, + description: 'This is an object parameter' + }, + parameterArray: { + type: [ + 'array', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is an array parameter' + }, + parameterDictionary: { + type: [ + 'object', + 'null' + ], + items: { + type: 'string' + }, + description: 'This is a dictionary parameter' + }, + parameterEnum: { + oneOf: [ + { + enum: [ + 'Success', + 'Warning', + 'Error' + ] + }, + { + type: 'null' + } + ], + description: 'This is an enum parameter' + } + }, + required: [ + 'parameterNumber', + 'parameterString', + 'parameterBoolean', + 'parameterObject', + 'parameterArray', + 'parameterDictionary', + 'parameterEnum' + ], + type: 'object' +} as const; + +export const UploadFilePathSchema = { + properties: { + 'api-version': { + type: [ + 'string', + 'null' + ], + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'api-version' + ], + type: 'object' +} as const; + +export const FileResponsePathSchema = { + properties: { + id: { + type: 'string' + }, + 'api-version': { + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'id', + 'api-version' + ], + type: 'object' +} as const; + +export const ComplexTypesQuerySchema = { + properties: { + parameterObject: { + type: 'object', + properties: { + first: { + type: 'object', + properties: { + second: { + type: 'object', + properties: { + third: { + type: 'string' + } + } + } + } + } + }, + description: 'Parameter containing object' + }, + parameterReference: { + $ref: '#/components/schemas/ModelWithString', + description: 'Parameter containing reference' + } + }, + required: [ + 'parameterObject', + 'parameterReference' + ], + type: 'object' +} as const; + +export const ComplexParamsPathSchema = { + properties: { + id: { + type: 'integer', + format: 'int32' + }, + 'api-version': { + type: 'string', + description: 'api-version should be required in standalone clients' + } + }, + required: [ + 'id', + 'api-version' + ], + type: 'object' +} as const; + +export const TestErrorCodeQuerySchema = { + properties: { + status: { + type: 'integer', + description: 'Status code to return' + } + }, + required: [ + 'status' + ], + type: 'object' +} as const; + +export const NonAsciiæøåÆøÅöôêÊ字符串QuerySchema = { + properties: { + nonAsciiParamæøåÆØÅöôêÊ: { + type: 'integer', + description: 'Dummy input param' + } + }, + required: [ + 'nonAsciiParamæøåÆØÅöôêÊ' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts new file mode 100644 index 0000000000..ba227aeb53 --- /dev/null +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/schemas/inline-schemas/schemas.gen.ts @@ -0,0 +1,68 @@ +// This file is auto-generated by @hey-api/openapi-ts + +export const CatSchema = { + type: 'object', + properties: { + id: { + type: 'integer' + }, + name: { + type: 'string' + } + } +} as const; + +export const GetCatsQuerySchema = { + properties: { + is_adopted: { + type: 'boolean', + description: 'Filter by adoption status' + }, + color: { + type: 'string', + description: 'Filter by fur color' + }, + vaccination: { + type: 'object', + additionalProperties: false, + required: [ + 'vaccine_name' + ], + properties: { + vaccine_name: { + type: 'string' + }, + dose_count: { + type: 'number' + } + } + } + }, + type: 'object' +} as const; + +export const GetCatsByCatIdHeadersSchema = { + properties: { + 'x-api-key': { + type: 'string', + description: 'API key for authentication' + } + }, + required: [ + 'x-api-key' + ], + type: 'object' +} as const; + +export const GetCatsByCatIdPathSchema = { + properties: { + cat_id: { + type: 'integer', + description: 'The ID of the cat' + } + }, + required: [ + 'cat_id' + ], + type: 'object' +} as const; diff --git a/packages/openapi-ts-tests/main/test/plugins.test.ts b/packages/openapi-ts-tests/main/test/plugins.test.ts index 426e15a52e..3b3f8d7fa1 100644 --- a/packages/openapi-ts-tests/main/test/plugins.test.ts +++ b/packages/openapi-ts-tests/main/test/plugins.test.ts @@ -427,6 +427,14 @@ for (const version of versions) { }), description: 'generate schemas', }, + { + config: createConfig({ + input: 'inline-schemas.yaml', + output: 'inline-schemas', + plugins: ['@hey-api/schemas'], + }), + description: 'generate schemas for inline parameter schemas', + }, { config: createConfig({ output: 'default', diff --git a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts index 985c2ed54e..8ab30b5ee4 100644 --- a/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts +++ b/packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts @@ -1,10 +1,19 @@ import type { Context, OpenApi } from '@hey-api/shared'; -import { satisfies } from '@hey-api/shared'; +import { satisfies, toCase } from '@hey-api/shared'; import type { OpenAPIV2, OpenAPIV3, OpenAPIV3_1 } from '@hey-api/spec-types'; import { $ } from '../../../ts-dsl'; import type { HeyApiSchemasPlugin } from './types'; +const httpMethods = ['delete', 'get', 'head', 'options', 'patch', 'post', 'put', 'trace'] as const; + +const paramLocations = [ + { location: 'cookie', suffix: 'Cookies' }, + { location: 'header', suffix: 'Headers' }, + { location: 'path', suffix: 'Path' }, + { location: 'query', suffix: 'Query' }, +] as const; + const stripSchema = ({ plugin, schema, @@ -340,10 +349,6 @@ const schemasV2_0_X = ({ context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { - if (!context.spec.definitions) { - return; - } - for (const name in context.spec.definitions) { const schema = context.spec.definitions[name]!; const symbol = plugin.symbol(schemaName({ name, plugin, schema }), { @@ -370,6 +375,100 @@ const schemasV2_0_X = ({ ); plugin.node(statement); } + + for (const path in context.spec.paths) { + if (path.startsWith('x-')) { + continue; + } + + const pathItem = context.spec.paths[path as `/${string}`]!; + + for (const method of httpMethods) { + const operation = pathItem[method as keyof typeof pathItem] as + | OpenAPIV2.OperationObject + | undefined; + if (!operation) { + continue; + } + + const irOperation = context.ir.paths?.[path as `/${string}`]?.[method]; + if (!irOperation) { + continue; + } + + for (const { location, suffix } of paramLocations) { + const params = new Map(); + + for (const param of pathItem.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param as OpenAPIV2.ParameterObject); + } + + for (const param of operation.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param as OpenAPIV2.ParameterObject); + } + + if (params.size === 0) { + continue; + } + + const properties: Record = {}; + const required: Array = []; + for (const [paramName, param] of params) { + if (!('type' in param)) { + continue; + } + const propSchema: Record = {}; + for (const [key, value] of Object.entries(param)) { + if (key === 'allowEmptyValue' || key === 'in' || key === 'name' || key === 'required') { + continue; + } + propSchema[key] = value; + } + properties[paramName] = propSchema as OpenAPIV2.SchemaObject; + if (param.required) { + required.push(paramName); + } + } + + const locationSchema = { + properties, + ...(required.length && { required }), + type: 'object', + } as OpenAPIV2.SchemaObject; + + const name = `${toCase(irOperation.id, 'PascalCase')}${suffix}`; + const symbol = plugin.symbol(schemaName({ name, plugin, schema: locationSchema }), { + meta: { + category: 'schema', + resource: 'operation', + resourceId: irOperation.id, + tool: 'json-schema', + }, + }); + const obj = schemaToJsonSchemaDraft_04({ + context, + plugin, + schema: locationSchema, + }); + const statement = $.const(symbol) + .export() + .assign( + $( + $.fromValue(obj, { + layout: 'pretty', + }), + ).as('const'), + ); + plugin.node(statement); + } + } + } }; const schemasV3_0_X = ({ @@ -379,12 +478,8 @@ const schemasV3_0_X = ({ context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { - if (!context.spec.components) { - return; - } - - for (const name in context.spec.components.schemas) { - const schema = context.spec.components.schemas[name]!; + for (const name in context.spec.components?.schemas) { + const schema = context.spec.components!.schemas![name]!; const symbol = plugin.symbol(schemaName({ name, plugin, schema }), { meta: { category: 'schema', @@ -409,6 +504,104 @@ const schemasV3_0_X = ({ ); plugin.node(statement); } + + for (const path in context.spec.paths) { + if (path.startsWith('x-')) { + continue; + } + + const pathItem = context.spec.paths[path as `/${string}`]!; + + for (const method of httpMethods) { + const operation = pathItem[method as keyof typeof pathItem] as + | OpenAPIV3.OperationObject + | undefined; + if (!operation) { + continue; + } + + const irOperation = context.ir.paths?.[path as `/${string}`]?.[method]; + if (!irOperation) { + continue; + } + + for (const { location, suffix } of paramLocations) { + const params = new Map(); + + for (const param of pathItem.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param); + } + + for (const param of operation.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param); + } + + if (params.size === 0) { + continue; + } + + const properties: Record = {}; + const required: Array = []; + for (const [paramName, param] of params) { + let propSchema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject | undefined; + if (param.schema) { + propSchema = { ...param.schema }; + if (param.description && !('$ref' in propSchema)) { + propSchema.description = param.description; + } + } else if (param.content) { + const mediaType = Object.values(param.content)[0]; + if (mediaType?.schema) { + propSchema = { ...mediaType.schema }; + } + } + if (propSchema) { + properties[paramName] = propSchema; + } + if (param.required) { + required.push(paramName); + } + } + + const locationSchema = { + properties, + ...(required.length && { required }), + type: 'object', + } as OpenAPIV3.SchemaObject; + + const name = `${toCase(irOperation.id, 'PascalCase')}${suffix}`; + const symbol = plugin.symbol(schemaName({ name, plugin, schema: locationSchema }), { + meta: { + category: 'schema', + resource: 'operation', + resourceId: irOperation.id, + tool: 'json-schema', + }, + }); + const obj = schemaToJsonSchemaDraft_05({ + context, + plugin, + schema: locationSchema, + }); + const statement = $.const(symbol) + .export() + .assign( + $( + $.fromValue(obj, { + layout: 'pretty', + }), + ).as('const'), + ); + plugin.node(statement); + } + } + } }; const schemasV3_1_X = ({ @@ -418,12 +611,8 @@ const schemasV3_1_X = ({ context: Context; plugin: HeyApiSchemasPlugin['Instance']; }) => { - if (!context.spec.components) { - return; - } - - for (const name in context.spec.components.schemas) { - const schema = context.spec.components.schemas[name]!; + for (const name in context.spec.components?.schemas) { + const schema = context.spec.components!.schemas![name]!; const symbol = plugin.symbol(schemaName({ name, plugin, schema }), { meta: { category: 'schema', @@ -448,6 +637,104 @@ const schemasV3_1_X = ({ ); plugin.node(statement); } + + for (const path in context.spec.paths) { + if (path.startsWith('x-')) { + continue; + } + + const pathItem = context.spec.paths![path as `/${string}`]!; + + for (const method of httpMethods) { + const operation = pathItem[method as keyof typeof pathItem] as + | OpenAPIV3_1.OperationObject + | undefined; + if (!operation) { + continue; + } + + const irOperation = context.ir.paths?.[path as `/${string}`]?.[method]; + if (!irOperation) { + continue; + } + + for (const { location, suffix } of paramLocations) { + const params = new Map(); + + for (const param of pathItem.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param); + } + + for (const param of operation.parameters ?? []) { + if ('$ref' in param || param.in !== location) { + continue; + } + params.set(param.name, param); + } + + if (params.size === 0) { + continue; + } + + const properties: Record = {}; + const required: Array = []; + for (const [paramName, param] of params) { + let propSchema: OpenAPIV3_1.SchemaObject | undefined; + if (param.schema) { + propSchema = { ...param.schema }; + if (param.description) { + propSchema.description = param.description; + } + } else if (param.content) { + const mediaType = Object.values(param.content)[0]; + if (mediaType?.schema) { + propSchema = { ...mediaType.schema }; + } + } + if (propSchema) { + properties[paramName] = propSchema; + } + if (param.required) { + required.push(paramName); + } + } + + const locationSchema = { + properties, + ...(required.length && { required }), + type: 'object', + } as OpenAPIV3_1.SchemaObject; + + const name = `${toCase(irOperation.id, 'PascalCase')}${suffix}`; + const symbol = plugin.symbol(schemaName({ name, plugin, schema: locationSchema }), { + meta: { + category: 'schema', + resource: 'operation', + resourceId: irOperation.id, + tool: 'json-schema', + }, + }); + const obj = schemaToJsonSchema2020_12({ + context, + plugin, + schema: locationSchema, + }); + const statement = $.const(symbol) + .export() + .assign( + $( + $.fromValue(obj, { + layout: 'pretty', + }), + ).as('const'), + ); + plugin.node(statement); + } + } + } }; export const handler: HeyApiSchemasPlugin['Handler'] = ({ plugin }) => { diff --git a/specs/2.0.x/inline-schemas.yaml b/specs/2.0.x/inline-schemas.yaml new file mode 100644 index 0000000000..fc0031e326 --- /dev/null +++ b/specs/2.0.x/inline-schemas.yaml @@ -0,0 +1,51 @@ +swagger: '2.0' +info: + title: Inline Schemas + version: v1 +host: localhost:3000 +basePath: /base +schemes: + - http +definitions: + Cat: + type: object + properties: + id: + type: integer + name: + type: string +paths: + /cats: + parameters: + - name: is_adopted + description: Filter by adoption status + in: query + type: boolean + required: false + get: + parameters: + - name: color + description: Filter by fur color + in: query + type: string + required: false + responses: + '200': + description: OK + /cats/{cat_id}: + parameters: + - name: cat_id + description: The ID of the cat + in: path + type: integer + required: true + get: + parameters: + - name: x-api-key + description: API key for authentication + in: header + type: string + required: true + responses: + '200': + description: OK diff --git a/specs/3.0.x/inline-schemas.yaml b/specs/3.0.x/inline-schemas.yaml new file mode 100644 index 0000000000..56e60eb076 --- /dev/null +++ b/specs/3.0.x/inline-schemas.yaml @@ -0,0 +1,75 @@ +openapi: 3.0.4 +info: + title: Inline Schemas + version: v1 +servers: + - url: http://localhost:3000/base +components: + schemas: + Cat: + type: object + properties: + id: + type: integer + name: + type: string +paths: + /cats: + parameters: + - name: is_adopted + description: Filter by adoption status + in: query + schema: + type: boolean + required: false + get: + parameters: + - name: color + description: Filter by fur color + in: query + schema: + type: string + required: false + - name: vaccination + in: query + content: + 'application/json': + schema: + type: object + additionalProperties: false + required: + - vaccine_name + properties: + vaccine_name: + type: string + dose_count: + type: number + required: false + responses: + '200': + description: OK + content: + 'application/json': + schema: {} + /cats/{cat_id}: + parameters: + - name: cat_id + description: The ID of the cat + in: path + schema: + type: integer + required: true + get: + parameters: + - name: x-api-key + description: API key for authentication + in: header + schema: + type: string + required: true + responses: + '200': + description: OK + content: + 'application/json': + schema: {} diff --git a/specs/3.1.x/inline-schemas.yaml b/specs/3.1.x/inline-schemas.yaml new file mode 100644 index 0000000000..951c8e0a0a --- /dev/null +++ b/specs/3.1.x/inline-schemas.yaml @@ -0,0 +1,73 @@ +openapi: 3.1.0 +info: + title: Inline Schemas + version: v1 +components: + schemas: + Cat: + type: object + properties: + id: + type: integer + name: + type: string +paths: + /cats: + parameters: + - name: is_adopted + description: Filter by adoption status + in: query + schema: + type: boolean + required: false + get: + parameters: + - name: color + description: Filter by fur color + in: query + schema: + type: string + required: false + - name: vaccination + in: query + content: + 'application/json': + schema: + type: object + additionalProperties: false + required: + - vaccine_name + properties: + vaccine_name: + type: string + dose_count: + type: number + required: false + responses: + '200': + description: OK + content: + 'application/json': + schema: {} + /cats/{cat_id}: + parameters: + - name: cat_id + description: The ID of the cat + in: path + schema: + type: integer + required: true + get: + parameters: + - name: x-api-key + description: API key for authentication + in: header + schema: + type: string + required: true + responses: + '200': + description: OK + content: + 'application/json': + schema: {}