Skip to content

Commit

Permalink
fix(type-safe-api): fix typescript handler dist path for operations w…
Browse files Browse the repository at this point in the history
…ith inline request bodies (#607)

When an operation has inline request body schemas (rather than a $ref) in OpenAPI, the operation ID
is suffixed with "Operation" in the generated code, but the operation nickname remains unchanged.
Previously, the operation ID was used for the handler dist reference in the generated functions, but
the nickname was used to generate the actual filename. Address this by using the nickname in both
places for typescript generated functions.

Fixes #606
  • Loading branch information
cogwirrel authored Oct 19, 2023
1 parent 17aa81b commit c922390
Show file tree
Hide file tree
Showing 8 changed files with 767 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class {{operationIdCamelCase}}Function extends {{#startsWith vendorExtens
code: Code.fromAsset(path.resolve(__dirname, "..",
{{#startsWith vendorExtensions.x-handler.language 'typescript' ~}}
"{{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-handlers-typescript-asset-path}}{{/apis.0}}{{/apiInfo}}",
"###TSAPI_FN###{ "function": "kebabCase", "args": ["{{operationIdCamelCase}}"] }###/TSAPI_FN###",
"###TSAPI_FN###{ "function": "kebabCase", "args": ["{{nickname}}"] }###/TSAPI_FN###",
{{~/startsWith}}{{#startsWith vendorExtensions.x-handler.language 'python' ~}}
"{{#apiInfo}}{{#apis.0}}{{vendorExtensions.x-handlers-python-asset-path}}{{/apis.0}}{{/apiInfo}}",
{{~/startsWith}}{{#startsWith vendorExtensions.x-handler.language 'java' ~}}
Expand Down
86 changes: 86 additions & 0 deletions packages/type-safe-api/test/resources/specs/inline-body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
openapi: 3.0.3
info:
version: 1.0.0
title: Test
paths:
/typescript:
post:
operationId: typescriptTest
x-handler:
language: typescript
requestBody:
required: true
content:
application/json:
# Schema is inline rather than a $ref
schema:
type: object
properties:
field1:
type: string
field2:
type: string
responses:
200:
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/TestResponseContent'
/java:
post:
operationId: javaTest
x-handler:
language: java
requestBody:
required: true
content:
application/json:
# Schema is inline rather than a $ref
schema:
type: object
properties:
field1:
type: string
field2:
type: string
responses:
200:
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/TestResponseContent'
/python:
post:
operationId: pythonTest
x-handler:
language: python
requestBody:
required: true
content:
application/json:
# Schema is inline rather than a $ref
schema:
type: object
properties:
field1:
type: string
field2:
type: string
responses:
200:
description: OK
content:
'application/json':
schema:
$ref: '#/components/schemas/TestResponseContent'
components:
schemas:
TestResponseContent:
type: object
properties:
message:
type: string
required:
- message
Loading

0 comments on commit c922390

Please sign in to comment.