Skip to content

Enhance getJsonSchema to describe navigational properties #2630

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

Closed
3 tasks
bajtos opened this issue Mar 22, 2019 · 5 comments · Fixed by #2975
Closed
3 tasks

Enhance getJsonSchema to describe navigational properties #2630

bajtos opened this issue Mar 22, 2019 · 5 comments · Fixed by #2975
Assignees
Labels
feature OpenAPI Relations Model relations (has many, etc.)

Comments

@bajtos
Copy link
Member

bajtos commented Mar 22, 2019

Improve the code converting LoopBack Model definitions into JSON Schema documents to optionally describe navigational properties for relations defined by the model. The decision is controlled by a new option passed to modelToJsonSchema and
related methods.

// own properties only
const spec = getJsonSchema(Product);
// include navigational properties too
const spec = getJsonSchema(Product, {includeRelations: true});

Add a new property to all relation definitions. This property will signal whether the relations is targeting a single model instance (e.g. BelongsTo, HasOne) or an array of instances (e.g. HasMany).

 export interface RelationDefinitionBase {
   /**
    * The type of the relation, must be one of RelationType values.
    */
   type: RelationType;

+  /**
+   * True for relations targeting multiple instances (e.g. HasMany),
+   * false for relations with a single target (e.g. BelongsTo, HasOne).
+   * This property is need by OpenAPI/JSON Schema generator.
+   */
+  targetsMany: boolean;

   // ...
}

Add a new property to options object used by getJsonSchema and modelToJsonSchema:

 export interface JsonSchemaOptions {
+  includeRelations?: boolean;
   visited?: {[key: string]: JSONSchema};
 }

Modify the implementation of modelToJsonSchema to include navigational properties when includeRelations is set.

See the spike #2592 and especially the commits 2256435 for more details. Please note the commit shows changes before the review feedback was applied. You need to review the final pull request diff of the PoC before copying any code over.

This story requires us to fix handling of circular references first, see #2628.

Acceptance criteria

  • Implement the changes described above
  • Test coverage
  • Update API documentation
@emonddr
Copy link
Contributor

emonddr commented Apr 2, 2019

@raymondfeng mentioned that the includeRelations should have the freedom to accept an array of relation names as well. A boolean field of includeRelations would mean we accept all relations.

includeRelations : true // includes all relations 
includeRelations: false // does not include any relations 
includeRelations:['rel1','rel2'] // includes these relations only.

@bajtos bajtos added the p1 label Apr 9, 2019
@bajtos
Copy link
Member Author

bajtos commented Apr 16, 2019

mentioned that the includeRelations should have the freedom to accept an array of relation names as well. A boolean field of includeRelations would mean we accept all relations.

Makes sense. Maybe we can leave this out of the initial implementation and wait until there is user demand for this more complex variant?

@dhmlau
Copy link
Member

dhmlau commented May 24, 2019

@samarpanB, I just assigned this issue to you, since you've indicated your interest to contribute: #1352 (comment).

@samarpanB
Copy link
Contributor

samarpanB commented May 25, 2019

Okay @dhmlau. @bajtos, I am going to need your guidance on this. I’ll follow what you have mentioned in the description. I’ll submit in-progress PR as soon as I get to something, so that you can review and let me know if I am on right track. Also if you want to provide me some heads up, please let me know.

@bajtos
Copy link
Member Author

bajtos commented May 27, 2019

@samarpanB I am happy to help, let me know if you run into any questions.

samarpanB added a commit to samarpanB/loopback-next that referenced this issue May 27, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 3, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 3, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 3, 2019
@nabdelgadir nabdelgadir added this to the June 2019 milestone milestone Jun 3, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 4, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 4, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 4, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 5, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 5, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 6, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 6, 2019
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 7, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 7, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 9, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 10, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
samarpanB added a commit to samarpanB/loopback-next that referenced this issue Jun 10, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix loopbackio#2630
nabdelgadir pushed a commit that referenced this issue Jun 10, 2019
…ational properties

Enhance `getJsonSchema` to describe navigational properties

fix #2630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature OpenAPI Relations Model relations (has many, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants