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

OpenApi #182

Open
kaldaf opened this issue Mar 28, 2022 · 3 comments
Open

OpenApi #182

kaldaf opened this issue Mar 28, 2022 · 3 comments

Comments

@kaldaf
Copy link

kaldaf commented Mar 28, 2022

Hey, i created my own openapi based on Alosaur:

swagger

But I would like to add parameters of any type: Request Body, Schemas, ...
example - https://petstore.swagger.io/
Is there example how to write it?
example

TO:
https://petstore.swagger.io/v2/swagger.json

Thanks.

@irustm
Copy link
Member

irustm commented Mar 28, 2022

Hi!
You can also add what media types can be expected in the body. Use RequestBody param in JsDoc

/**
   * Create product
   * @param product
   * @RequestBody application/xml
   * @RequestBody application/json
   */
  @Post("/")
  Create(@Body() product: Product) {
  }

You can also add what types can be returned from a controller method. Use decorator ProducesResponse

/**
 * Gets product by id
 * @summary action test
 * @remarks Awesomeness!
 * @param {id} The product id
 */
@Get("/:id")
@ProducesResponse({ code: 200, type: Product, description: "Product found" })
@ProducesResponse({ code: 404, type: NotFoundResult, description: "Product has missing/invalid values" })
@ProducesResponse({ code: 500, description: "Oops! Can't create your product right now" })
GetById(@Param("id") id: string) {
  return new Product();
}

To declare more information in types and models you can add other JsDoc parameters

/**
 * Entity of product
 */
export class Product {
  /**
   * @summary Identifer of code
   * @example 1
   */
  id?: number;

  /**
   * @summary Array of test case
   * @example [1,2,3]
   */
  arr?: number[];

  /**
   * @summary Type of product
   * @example {id:1}
   */
  type?: ProductType;

  /**
   * @maximum 100
   */
  count?: number;
}```

https://github.com/alosaur/alosaur.com/blob/main/docs/techniques/OpenAPI.md

@kaldaf
Copy link
Author

kaldaf commented Mar 29, 2022

Oh, my bad I'm blind 😃...
How to import ProducesResponse? When I import this like that:
import { ProducesResponse } from "https://deno.land/x/alosaur/openapi/mod.ts"
It returns error:
TS2305 [ERROR]: Module '"https://deno.land/x/[email protected]/openapi/mod.ts"' has no exported member 'ProducesResponse'.

Should I copy the metadata folder where ProducesResponse is?

Thanks.

@irustm
Copy link
Member

irustm commented Mar 29, 2022

That would work:
import {ProducesResponse} https://deno.land/x/[email protected]/openapi/metadata/produces-response.decorator.ts

But I think it would have to be improved to this state

import { ProducesResponse } from "https://deno.land/x/alosaur/openapi/mod.ts"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants