Skip to content

Commit

Permalink
docs(examples): update sample output generator to include new associa…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
bravo-kernel committed Nov 6, 2019
1 parent 7b91090 commit 067c1e8
Show file tree
Hide file tree
Showing 3 changed files with 409 additions and 57 deletions.
74 changes: 59 additions & 15 deletions examples/generate.js
Expand Up @@ -22,19 +22,26 @@ const schemaManager = new JsonSchemaManager({
// ----------------------------------------------------------------------------
// JSON Schema Draft-07
// ----------------------------------------------------------------------------
let userSchema = schemaManager.generate(models.user, new JsonSchema7Strategy(), {
let strategy = new JsonSchema7Strategy();

let userSchema = schemaManager.generate(models.user, strategy, {
title: 'Custom Title',
description: 'Custom Description',
});

let profileSchema = schemaManager.generate(models.profile, new JsonSchema7Strategy());
let documentSchema = schemaManager.generate(models.document, new JsonSchema7Strategy());
let profileSchema = schemaManager.generate(models.profile, strategy);
let documentSchema = schemaManager.generate(models.document, strategy);
let companySchema = schemaManager.generate(models.company, strategy);
let friendshipSchema = schemaManager.generate(models.friendship, strategy);

let fullSchema = {
$schema: 'https://json-schema.org/draft-07/schema#',
definitions: {
users: userSchema,
profiles: profileSchema,
documents: documentSchema,
user: userSchema,
profile: profileSchema,
document: documentSchema,
company: companySchema,
friendship: friendshipSchema,
},
};

Expand Down Expand Up @@ -71,6 +78,22 @@ ${JSON.stringify(documentSchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Company Model
<!-- prettier-ignore-start -->
\`\`\`json
${JSON.stringify(companySchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Friendship Model
<!-- prettier-ignore-start -->
\`\`\`json
${JSON.stringify(friendshipSchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Full Schema
Please note that sequelize-to-json-schemas does NOT generate full schemas. This is just an
Expand All @@ -95,21 +118,26 @@ console.log('Succesfully generated markdown sample output for JSON Schema Draft-
// ----------------------------------------------------------------------------
// OpenAPI 3.0
// ----------------------------------------------------------------------------
const openapi3strategy = new OpenApi3Strategy();
userSchema = schemaManager.generate(models.user, openapi3strategy, {
title: 'Custom Title',
description: 'Custom Description',
strategy = new OpenApi3Strategy();

userSchema = schemaManager.generate(models.user, strategy, {
title: 'Custom User Title',
description: 'Custom User Description',
});

profileSchema = schemaManager.generate(models.profile, openapi3strategy);
documentSchema = schemaManager.generate(models.document, openapi3strategy);
profileSchema = schemaManager.generate(models.profile, strategy);
documentSchema = schemaManager.generate(models.document, strategy);
companySchema = schemaManager.generate(models.company, strategy);
friendshipSchema = schemaManager.generate(models.friendship, strategy);

fullSchema = require('../test/strategies/openapi-v3-validation-wrapper');

fullSchema.components.schemas = {
users: userSchema,
profiles: profileSchema,
documents: documentSchema,
user: userSchema,
profile: profileSchema,
document: documentSchema,
company: companySchema,
friendship: friendshipSchema,
};

markdown = `# OpenAPI 3.0
Expand Down Expand Up @@ -146,6 +174,22 @@ ${JSON.stringify(documentSchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Company Model
<!-- prettier-ignore-start -->
\`\`\`json
${JSON.stringify(companySchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Friendship Model
<!-- prettier-ignore-start -->
\`\`\`json
${JSON.stringify(friendshipSchema, null, 2)}
\`\`\`
<!-- prettier-ignore-end -->
## Full Schema
Please note that sequelize-to-json-schemas does NOT generate full schemas. This is just an
Expand Down
198 changes: 188 additions & 10 deletions examples/json-schema-v7.md
@@ -1,6 +1,6 @@
# JSON Schema Draft-07

These schemas were automatically generated on 2019-11-01
These schemas were automatically generated on 2019-11-06
using [these Sequelize models](../test/models) and the most recent version of
sequelize-to-json-schemas. To confirm that these are indeed all valid schemas use:

Expand Down Expand Up @@ -130,15 +130,51 @@ sequelize-to-json-schemas. To confirm that these are indeed all valid schemas us
"type": "string",
"writeOnly": true
},
"companyId": {
"$id": "https://api.example.com/properties/companyId",
"type": [
"integer",
"null"
],
"format": "int32"
},
"bossId": {
"$id": "https://api.example.com/properties/bossId",
"type": [
"integer",
"null"
],
"format": "int32"
},
"profile": {
"$ref": "#/definitions/profiles"
"$ref": "#/definitions/profile"
},
"company": {
"$ref": "#/definitions/company"
},
"documents": {
"type": "array",
"items": {
"oneOf": [
"$ref": "#/definitions/document"
}
},
"boss": {
"$ref": "#/definitions/user"
},
"friends": {
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/definitions/documents"
"$ref": "#/definitions/user"
},
{
"type": "object",
"properties": {
"friendships": {
"$ref": "#/definitions/friendship"
}
}
}
]
}
Expand Down Expand Up @@ -227,6 +263,66 @@ sequelize-to-json-schemas. To confirm that these are indeed all valid schemas us
```
<!-- prettier-ignore-end -->

## Company Model

<!-- prettier-ignore-start -->
```json
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/company.json",
"title": "Company",
"type": "object",
"properties": {
"id": {
"$id": "https://api.example.com/properties/id",
"type": "integer",
"format": "int32"
},
"name": {
"$id": "https://api.example.com/properties/name",
"type": "string"
}
},
"required": [
"id"
]
}
```
<!-- prettier-ignore-end -->

## Friendship Model

<!-- prettier-ignore-start -->
```json
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/friendship.json",
"title": "Friendship",
"type": "object",
"properties": {
"isBestFriend": {
"$id": "https://api.example.com/properties/isBestFriend",
"type": "boolean",
"default": false
},
"userId": {
"$id": "https://api.example.com/properties/userId",
"type": "integer",
"format": "int32"
},
"friendId": {
"$id": "https://api.example.com/properties/friendId",
"type": "integer",
"format": "int32"
}
},
"required": [
"isBestFriend"
]
}
```
<!-- prettier-ignore-end -->

## Full Schema

Please note that sequelize-to-json-schemas does NOT generate full schemas. This is just an
Expand All @@ -238,7 +334,7 @@ document (by adding model schemas to `definitions`).
{
"$schema": "https://json-schema.org/draft-07/schema#",
"definitions": {
"users": {
"user": {
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/user.json",
"title": "Custom Title",
Expand Down Expand Up @@ -357,15 +453,51 @@ document (by adding model schemas to `definitions`).
"type": "string",
"writeOnly": true
},
"companyId": {
"$id": "https://api.example.com/properties/companyId",
"type": [
"integer",
"null"
],
"format": "int32"
},
"bossId": {
"$id": "https://api.example.com/properties/bossId",
"type": [
"integer",
"null"
],
"format": "int32"
},
"profile": {
"$ref": "#/definitions/profiles"
"$ref": "#/definitions/profile"
},
"company": {
"$ref": "#/definitions/company"
},
"documents": {
"type": "array",
"items": {
"oneOf": [
"$ref": "#/definitions/document"
}
},
"boss": {
"$ref": "#/definitions/user"
},
"friends": {
"type": "array",
"items": {
"allOf": [
{
"$ref": "#/definitions/user"
},
{
"$ref": "#/definitions/documents"
"type": "object",
"properties": {
"friendships": {
"$ref": "#/definitions/friendship"
}
}
}
]
}
Expand All @@ -381,7 +513,7 @@ document (by adding model schemas to `definitions`).
"CUSTOM_WRITEONLY"
]
},
"profiles": {
"profile": {
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/profile.json",
"title": "Profile",
Expand Down Expand Up @@ -409,7 +541,7 @@ document (by adding model schemas to `definitions`).
"id"
]
},
"documents": {
"document": {
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/document.json",
"title": "Document",
Expand All @@ -436,6 +568,52 @@ document (by adding model schemas to `definitions`).
"required": [
"id"
]
},
"company": {
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/company.json",
"title": "Company",
"type": "object",
"properties": {
"id": {
"$id": "https://api.example.com/properties/id",
"type": "integer",
"format": "int32"
},
"name": {
"$id": "https://api.example.com/properties/name",
"type": "string"
}
},
"required": [
"id"
]
},
"friendship": {
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://api.example.com/friendship.json",
"title": "Friendship",
"type": "object",
"properties": {
"isBestFriend": {
"$id": "https://api.example.com/properties/isBestFriend",
"type": "boolean",
"default": false
},
"userId": {
"$id": "https://api.example.com/properties/userId",
"type": "integer",
"format": "int32"
},
"friendId": {
"$id": "https://api.example.com/properties/friendId",
"type": "integer",
"format": "int32"
}
},
"required": [
"isBestFriend"
]
}
}
}
Expand Down

0 comments on commit 067c1e8

Please sign in to comment.