Skip to content

Commit fc0566e

Browse files
authored
fix: Use post operation for createEndpoint (#209)
1 parent b93bd4b commit fc0566e

File tree

4 files changed

+139
-5
lines changed

4 files changed

+139
-5
lines changed

src/lib/blueprint.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -675,10 +675,10 @@ const createEndpoint = async (
675675
([method]) => method.toUpperCase() as Method,
676676
)
677677

678-
const validOperation = validOperations[0]
678+
const validOperation = validOperations.find(([m]) => m === 'post')
679679
if (validOperation == null) {
680680
// eslint-disable-next-line no-console
681-
console.warn(`No valid operations found for ${path}`)
681+
console.warn(`No valid post operation found for ${path}`)
682682

683683
return null
684684
}
@@ -811,7 +811,7 @@ export const getWorkspaceScope = (
811811
return 'none'
812812
}
813813

814-
export const createRequest = (
814+
const createRequest = (
815815
methods: Method[],
816816
operation: OpenapiOperation,
817817
path: string,

test/fixtures/types/openapi.ts

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ export default {
335335
400: { description: 'Bad Request' },
336336
401: { description: 'Unauthorized' },
337337
},
338-
security: [],
338+
security: [
339+
{
340+
api_key: [],
341+
},
342+
],
339343
summary: '/foos/get',
340344
tags: ['/foos'],
341345
'x-response-key': 'foo',
@@ -428,6 +432,9 @@ export default {
428432
items: { $ref: '#/components/schemas/foo' },
429433
type: 'array',
430434
},
435+
pagination: {
436+
$ref: '#/components/schemas/pagination',
437+
},
431438
},
432439
required: ['foos', 'ok'],
433440
type: 'object',
@@ -439,7 +446,14 @@ export default {
439446
400: { description: 'Bad Request' },
440447
401: { description: 'Unauthorized' },
441448
},
442-
security: [],
449+
security: [
450+
{
451+
api_key: [],
452+
},
453+
{
454+
client_session: [],
455+
},
456+
],
443457
summary: '/foos/list',
444458
tags: ['/foos'],
445459
'x-response-key': 'foos',
@@ -478,6 +492,37 @@ export default {
478492
'x-response-key': 'foo',
479493
'x-title': 'Get a foo',
480494
},
495+
post: {
496+
operationId: 'foosAdvancedGetPost',
497+
responses: {
498+
200: {
499+
content: {
500+
'application/json': {
501+
schema: {
502+
properties: {
503+
ok: { type: 'boolean' },
504+
foo: { $ref: '#/components/schemas/foo' },
505+
},
506+
required: ['foo', 'ok'],
507+
type: 'object',
508+
},
509+
},
510+
},
511+
description: 'Get a foo by ID.',
512+
},
513+
400: { description: 'Bad Request' },
514+
401: { description: 'Unauthorized' },
515+
},
516+
security: [
517+
{
518+
api_key: [],
519+
},
520+
],
521+
summary: '/foos/advanced/get',
522+
tags: ['/foos/advanced'],
523+
'x-response-key': 'foo',
524+
'x-title': 'Get a foo',
525+
},
481526
},
482527
'/transport/air/planes/list': {
483528
get: {
@@ -510,6 +555,36 @@ export default {
510555
'x-response-key': 'planes',
511556
'x-title': 'List planes',
512557
},
558+
post: {
559+
operationId: 'planesListPost',
560+
responses: {
561+
200: {
562+
content: {
563+
'application/json': {
564+
schema: {
565+
properties: {
566+
ok: { type: 'boolean' },
567+
planes: {
568+
items: { $ref: '#/components/schemas/plane' },
569+
type: 'array',
570+
},
571+
},
572+
required: ['planes', 'ok'],
573+
type: 'object',
574+
},
575+
},
576+
},
577+
description: 'List all planes.',
578+
},
579+
400: { description: 'Bad Request' },
580+
401: { description: 'Unauthorized' },
581+
},
582+
security: [],
583+
summary: '/transport/air/planes/list',
584+
tags: ['/transport/air/planes'],
585+
'x-response-key': 'planes',
586+
'x-title': 'List planes',
587+
},
513588
},
514589
'/deprecated/undocumented/endpoint': {
515590
get: {
@@ -538,6 +613,32 @@ export default {
538613
'x-undocumented': 'true',
539614
'x-title': 'Deprecated and undocumented endpoint',
540615
},
616+
post: {
617+
operationId: 'deprecatedUndocumentedEndpointPost',
618+
deprecated: true,
619+
responses: {
620+
200: {
621+
content: {
622+
'application/json': {
623+
schema: {
624+
properties: {
625+
ok: { type: 'boolean' },
626+
},
627+
required: ['ok'],
628+
type: 'object',
629+
},
630+
},
631+
},
632+
description: 'Deprecated and undocumented endpoint',
633+
},
634+
},
635+
security: [],
636+
summary: '/deprecated/undocumented/endpoint',
637+
tags: ['/deprecated/undocumented'],
638+
'x-response-key': null,
639+
'x-undocumented': 'true',
640+
'x-title': 'Deprecated and undocumented endpoint',
641+
},
541642
},
542643
'/draft/endpoint': {
543644
get: {
@@ -565,6 +666,31 @@ export default {
565666
'x-draft': 'true',
566667
'x-title': 'Draft endpoint',
567668
},
669+
post: {
670+
operationId: 'draftEndpointPost',
671+
responses: {
672+
200: {
673+
content: {
674+
'application/json': {
675+
schema: {
676+
properties: {
677+
ok: { type: 'boolean' },
678+
},
679+
required: ['ok'],
680+
type: 'object',
681+
},
682+
},
683+
},
684+
description: 'Draft endpoint',
685+
},
686+
},
687+
security: [],
688+
summary: '/draft/endpoint',
689+
tags: ['/draft'],
690+
'x-response-key': null,
691+
'x-draft': 'true',
692+
'x-title': 'Draft endpoint',
693+
},
568694
},
569695
'/action_attempts/get': {
570696
post: {

test/snapshots/blueprint.test.ts.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,7 @@ Generated by [AVA](https://avajs.dev).
963963
request: {
964964
methods: [
965965
'GET',
966+
'POST',
966967
],
967968
parameters: [],
968969
preferredMethod: 'GET',
@@ -1108,6 +1109,7 @@ Generated by [AVA](https://avajs.dev).
11081109
request: {
11091110
methods: [
11101111
'GET',
1112+
'POST',
11111113
],
11121114
parameters: [],
11131115
preferredMethod: 'GET',
@@ -1245,6 +1247,7 @@ Generated by [AVA](https://avajs.dev).
12451247
request: {
12461248
methods: [
12471249
'GET',
1250+
'POST',
12481251
],
12491252
parameters: [],
12501253
preferredMethod: 'GET',
@@ -1379,6 +1382,7 @@ Generated by [AVA](https://avajs.dev).
13791382
request: {
13801383
methods: [
13811384
'GET',
1385+
'POST',
13821386
],
13831387
parameters: [],
13841388
preferredMethod: 'GET',
@@ -2446,6 +2450,7 @@ Generated by [AVA](https://avajs.dev).
24462450
request: {
24472451
methods: [
24482452
'GET',
2453+
'POST',
24492454
],
24502455
parameters: [],
24512456
preferredMethod: 'GET',
@@ -2609,6 +2614,7 @@ Generated by [AVA](https://avajs.dev).
26092614
request: {
26102615
methods: [
26112616
'GET',
2617+
'POST',
26122618
],
26132619
parameters: [],
26142620
preferredMethod: 'GET',
@@ -2764,6 +2770,7 @@ Generated by [AVA](https://avajs.dev).
27642770
request: {
27652771
methods: [
27662772
'GET',
2773+
'POST',
27672774
],
27682775
parameters: [],
27692776
preferredMethod: 'GET',
@@ -2916,6 +2923,7 @@ Generated by [AVA](https://avajs.dev).
29162923
request: {
29172924
methods: [
29182925
'GET',
2926+
'POST',
29192927
],
29202928
parameters: [],
29212929
preferredMethod: 'GET',
46 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)