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

Generate OpenAPI schema for Model properties of built-in JavaScript/Node.js types #1112

Closed
5 of 11 tasks
jannyHou opened this issue Mar 9, 2018 · 8 comments
Closed
5 of 11 tasks
Assignees
Labels
REST Issues related to @loopback/rest package and REST transport in general

Comments

@jannyHou
Copy link
Contributor

jannyHou commented Mar 9, 2018

cc @dhmlau

Description / Steps to reproduce / Feature proposal

import {model, property, DateType, Entity} from '@loopback/repository';

@model()
class Test extends Entity {
  @property()
  date: DateType
};

Current Behaviour

Since DateType is not a class decorated by @model, the generated OpenAPI spec doesn't generate schema for it in components.schemas

Expected Behaviour

automatically generate a schema entry in components.schemas for it.

Some proposal:

  • Discovering datatype and generating schema/definition could happen when generate jsonDef or oai3Spec, which one is better?

Acceptance Criteria:

  • For a model property in Loopback type(would be the types in @loopback/types), we automatically generate the openapi spec for it.

  • For example:

// Given a class with properties in Loopback types
@model
class Test {
  @property
  date: Date
  @property
  text: Buffer
}

// The generated schema for model Test should be
{
  schemas: {
    Test: {
      type: 'object',
      properties: {
        date: {type: 'string', format: 'date'},
        text: {type: 'string', format: 'buffer'}
      }
    }
  }
}
  • For each Loopback type, we can either map it to a simple schema like
schema: {type: string, format: 'date'}

or a schema reference

components: {
  schemas: {
    Date: {type: string, format: 'date'}
  }
}

People who works on this story can decide per type which approach is better. Types in scope:

  • date
  • boolean
  • number
  • string

Nice to have:

  • DateTime (the class defined in juggler)
  • buffer
  • object
  • GeoPoint
  • ObjectID
  • any model
@jannyHou jannyHou added the REST Issues related to @loopback/rest package and REST transport in general label Mar 9, 2018
@dhmlau dhmlau added the DP3 label Apr 19, 2018
@shimks
Copy link
Contributor

shimks commented May 22, 2018

I want to say this is covered by #1306. What do you think @jannyHou ?

@jannyHou
Copy link
Contributor Author

@shimks I think this issue is the conversion from model class to openapi spec, while #1306 is for the conversion from request to controller method's input, so they are different things.

@shimks
Copy link
Contributor

shimks commented May 28, 2018

Personally, I see Date as something that LoopBack should convert from what's been given as a string (see https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14). How do you feel?

@jannyHou
Copy link
Contributor Author

jannyHou commented Jun 4, 2018

@shimks I updated the acceptance criteria in #1112 (comment), hope it clarifies the use case need to fix in this story.
I feel you still misunderstand the use case here, this story has nothing to do with request/response/coercion, it's all about fixing the generated OAI3 schema for a given model, it's not related to a run-time http request...

@shimks
Copy link
Contributor

shimks commented Jun 4, 2018

I understand that Date schema is missing, what I'm saying is that we may not need one anymore considering we're allowing the users to pass in an instance of Date as a string. Maybe we should still provide a schema for it if we want to allow the users to provide Date as an object. Thoughts @strongloop/sq-lb-apex, @raymondfeng, @bajtos?

@bajtos
Copy link
Member

bajtos commented Jun 5, 2018

My opinion: If a remote method expects a date string in the input arguments, then the OpenAPI spec schema produced by LoopBack should clearly say so (so that clients understand what kind of a string to provide) and our REST layer should convert and validate the input value from string to a Date instance.

@dhmlau dhmlau added p2 and removed DP3 labels Jun 12, 2018
@jannyHou
Copy link
Contributor Author

jannyHou commented Jun 12, 2018

The description doesn't contain background info for people who's new to the rest decorators. FYI, here is a blog depicts how the OpenAPI concept is applied in LB4:
https://strongloop.com/strongblog/upgrade-from-swagger-to-openapi-3/

And also a list of related packages:

  • @loopback/openapi-v3
  • @loopback/openapi-v3-types
  • @loopback/openapi-spec-builder
  • @loopback/rest

@bajtos bajtos added the Core-GA label Jun 25, 2018
@bajtos bajtos changed the title Add jsonDef or OpenAPI schema for internal types in @loopback/repository Generate OpenAPI schema for Model properties using built-in JavaScript/Node.js types Jul 30, 2018
@bajtos bajtos changed the title Generate OpenAPI schema for Model properties using built-in JavaScript/Node.js types Generate OpenAPI schema for Model properties of built-in JavaScript/Node.js types Jul 30, 2018
@bajtos bajtos added the p1 label Aug 13, 2018
@dhmlau dhmlau removed the non-DP3 label Aug 23, 2018
@hacksparrow hacksparrow self-assigned this Sep 14, 2018
@hacksparrow
Copy link
Contributor

Fixed in #1731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REST Issues related to @loopback/rest package and REST transport in general
Projects
None yet
Development

No branches or pull requests

5 participants