Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [type-safe-api] Error: Path /path contains unsupported methods summary, description, parameters. Supported methods are get, put, post, delete, options, head, patch, trace. #662

Closed
valebedu opened this issue Nov 28, 2023 · 2 comments · Fixed by #673
Labels
bug Something isn't working needs-triage

Comments

@valebedu
Copy link
Contributor

valebedu commented Nov 28, 2023

Describe the bug

When building a type-safe-api project with a valid OAS file with summary, description and/or parameters under a path, the build fail with error:

Error: Path /path contains unsupported methods summary, description, parameters. Supported methods are get, put, post, delete, options, head, patch, trace.

Expected Behavior

Theses fields should not be treated as methods

Current Behavior

The build fail with error:

@acme/infra: /Users/johndoe/Workspace/acme/api/template-api/node_modules/.pnpm/@aws+pdk@0.22.42_@aws-cdk+aws-cognito-identitypool-alpha@2.104.0-alpha.0_@pnpm+logger@5.0.0_@_rhxgvbrzwsnk24l3fokhskptm4/node_modules/@aws/pdk/type-safe-api/construct/prepare-spec-event-handler/prepare-spec.ts:309
@acme/infra:     throw new Error(
@acme/infra:           ^
@acme/infra: Error: Path /info contains unsupported methods summary, description. Supported methods are get, put, post, delete, options, head, patch, trace.
@acme/infra:     at preparePathSpec (/Users/johndoe/Workspace/acme/api/template-api/node_modules/.pnpm/@aws+pdk@0.22.42_@aws-cdk+aws-cognito-identitypool-alpha@2.104.0-alpha.0_@pnpm+logger@5.0.0_@_rhxgvbrzwsnk24l3fokhskptm4/node_modules/@aws/pdk/type-safe-api/construct/prepare-spec-event-handler/prepare-spec.ts:309:11)
@acme/infra:     at /Users/johndoe/Workspace/acme/api/template-api/node_modules/.pnpm/@aws+pdk@0.22.42_@aws-cdk+aws-cognito-identitypool-alpha@2.104.0-alpha.0_@pnpm+logger@5.0.0_@_rhxgvbrzwsnk24l3fokhskptm4/node_modules/@aws/pdk/type-safe-api/construct/prepare-spec-event-handler/prepare-spec.ts:569:11
@acme/infra:     at Array.map (<anonymous>)
@acme/infra:     at prepareApiSpec (/Users/johndoe/Workspace/acme/api/template-api/node_modules/.pnpm/@aws+pdk@0.22.42_@aws-cdk+aws-cognito-identitypool-alpha@2.104.0-alpha.0_@pnpm+logger@5.0.0_@_rhxgvbrzwsnk24l3fokhskptm4/node_modules/@aws/pdk/type-safe-api/construct/prepare-spec-event-handler/prepare-spec.ts:567:36)
@acme/infra:     at new TypeSafeRestApi (/Users/johndoe/Workspace/acme/api/template-api/node_modules/.pnpm/@aws+pdk@0.22.42_@aws-cdk+aws-cognito-identitypool-alpha@2.104.0-alpha.0_@pnpm+logger@5.0.0_@_rhxgvbrzwsnk24l3fokhskptm4/node_modules/@aws/pdk/type-safe-api/construct/type-safe-rest-api.ts:334:51)
@acme/infra:     at new Api (/Users/johndoe/Workspace/acme/api/template-api/packages/api/generated/infrastructure/typescript/src/api.ts:18:5)
@acme/infra:     at new ApiConstruct (/Users/johndoe/Workspace/acme/api/template-api/packages/api-infra/src/constructs/api.ts:43:16)
@acme/infra:     at new ApplicationStack (/Users/johndoe/Workspace/acme/api/template-api/packages/api-infra/src/stacks/application-stack.ts:17:5)
@acme/infra:     at /Users/johndoe/Workspace/acme/api/template-api/packages/api-infra/src/main.ts:24:3
@acme/infra:     at Object.<anonymous> (/Users/johndoe/Workspace/acme/api/template-api/packages/api-infra/src/main.ts:41:3)

Reproduction Steps

With the default projenrc.ts

import { MonorepoTsProject } from "@aws/pdk/monorepo";
import {
  DocumentationFormat,
  Language,
  Library,
  ModelLanguage,
  TypeSafeApiProject,
} from "@aws/pdk/type-safe-api";
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";

// Create the monorepo
const monorepo = new MonorepoTsProject({
  name: "my-project",
  devDeps: [
    "@aws/pdk",
  ],
});

// Create the API project
const api = new TypeSafeApiProject({
  name: "myapi",
  parent: monorepo,
  outdir: "packages/api",
  // Smithy as the model language. You can also use ModelLanguage.OPENAPI
  model: {
    language: ModelLanguage.OPENAPI,
    options: {
      openapi: {
        title: 'Sample API',
      },
    },
  },
  // CDK infrastructure in TypeScript
  infrastructure: {
    language: Language.TYPESCRIPT,
  },
  // Lambda handlers in TypeScript
  handlers: {
    languages: [Language.TYPESCRIPT],
  }
  // Generate HTML documentation
  documentation: {
    formats: [DocumentationFormat.HTML_REDOC],
  },
  // Generate react-query hooks to interact with the UI from a React website
  library: {
    libraries: [Library.TYPESCRIPT_REACT_QUERY_HOOKS],
  },
});

// Create a CDK infrastructure project
new InfrastructureTsProject({
    parent: monorepo,
    outdir: "packages/infra",
    name: "infra",
    typeSafeApi: api,
});

monorepo.synth();

Run pdk

Then add in main.yaml under a path:

summary: Summary
description: Description
parameters:
  name: query
  in: query
  description: Query parameter
  required: false
  schema:
    type: string

Run pdk build

Please note that this is supported in official OAS https://spec.openapis.org/oas/latest.html#pathItemObject

Possible Solution

No response

Additional Information/Context

No response

PDK version used

0.22.42

What languages are you seeing this issue on?

Typescript

Environment details (OS name and version, etc.)

macOS Sonoma 14.1.1 Apple M1 Pro

@valebedu valebedu added bug Something isn't working needs-triage labels Nov 28, 2023
@valebedu valebedu changed the title [BUG] Error: Path /path contains unsupported methods summary, description, parameters. Supported methods are get, put, post, delete, options, head, patch, trace. [BUG] [type-safe-api] Error: Path /path contains unsupported methods summary, description, parameters. Supported methods are get, put, post, delete, options, head, patch, trace. Nov 28, 2023
@cogwirrel
Copy link
Member

Thanks for raising this! Looks like summary, description and parameters are also supported under a path in OpenAPI 3.0.3 which is the version we officially support!

cogwirrel added a commit that referenced this issue Dec 28, 2023
…ption

The OpenAPI specification permits parameters, summary and description to be defined at the path
level, and these apply for all methods under that path. The TypeSafeRestApi construct was
incorrectly throwing a validation error when any of these were specified. This change adjusts the
validation to still catch unsupported methods (such as 'any') while permitting these valid path
level properties.

Fixes #662
cogwirrel added a commit that referenced this issue Dec 28, 2023
…ption (#673)

The OpenAPI specification permits parameters, summary and description to be defined at the path
level, and these apply for all methods under that path. The TypeSafeRestApi construct was
incorrectly throwing a validation error when any of these were specified. This change adjusts the
validation to still catch unsupported methods (such as 'any') while permitting these valid path
level properties.

Fixes #662
@cogwirrel
Copy link
Member

Fixed in 0.22.48 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants