Skip to content

Latest commit

 

History

History
1342 lines (955 loc) · 39.6 KB

API.md

File metadata and controls

1342 lines (955 loc) · 39.6 KB

Classes

AbstractGenerator

Abstract generator which must be implemented by each language

AbstractRenderer

Abstract renderer with common helper methods

AsyncapiV2Schema

AsyncAPI schema model

Based on Draft 7 with additions

https://www.asyncapi.com/docs/specifications/v2.0.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.1.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.2.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.3.0#schemaObject

CommonInputModel

This class is the wrapper for simplified models and the rest of the context needed for further generate typed models.

CommonModel

Common internal representation for a model.

Draft4Schema

JSON Draft 4 schema model

Draft6Schema

JSON Draft 6 schema model

Draft7Schema

JSON Draft7Schema Draft 7 model

OpenapiV3Schema

OpenAPI 3.0 -> 3.0.4 schema model

Based on Draft 6, but with restricted keywords and definitions Modifications

  • type, cannot be an array nor contain 'null'

Restrictions (keywords not allowed)

  • patternProperties
  • not

https://swagger.io/specification/#schema-object

OutputModel

Common representation for the output model.

RenderOutput

Common representation for the rendered output.

SwaggerV2Schema

OpenAPI 2.0 (Swagger 2.0) schema model

Based on Draft 4, but with restricted keywords and definitions

Restrictions (keywords not allowed)

  • oneOf
  • anyOf
  • patternProperties
  • not

https://swagger.io/specification/v2/#schemaObject

AsyncAPIInputProcessor

Class for processing AsyncAPI inputs

InputProcessor

Main input processor which figures out the type of input it receives and delegates the processing into separate individual processors.

JsonSchemaInputProcessor

Class for processing JSON Schema

OpenAPIInputProcessor

Class for processing OpenAPI V3.0 inputs

SwaggerInputProcessor

Class for processing Swagger inputs

LoggerClass

Logger class for the model generation library

This class acts as a forefront for any external loggers which is why it also implements the interface itself.

Members

DefaultPropertyNames

Default property names for different aspects of the common model

CommonNamingConventionImplementation

A CommonNamingConvention implementation shared between generators for different languages.

Functions

getUniquePropertyName(rootModel, propertyName)

Recursively find the proper property name.

This function ensures that the property name is unique for the model

hasPreset(presets, preset)

Returns true if and only if a given preset is already included in a list of presets Check is done using referential equality

interpretAdditionalItems(schema, model, interpreter, interpreterOptions)

Interpreter function for additionalItems keyword.

interpretAdditionalProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for additionalProperties keyword.

interpretAllOf(schema, model, interpreter, interpreterOptions)

Interpreter function for allOf keyword.

It either merges allOf schemas into existing model or if allowed, create inheritance.

interpretConst(schema, model)

Interpreter function for const keyword for draft version > 4

interpretDependencies(schema, model)

Interpreter function for dependencies keyword.

interpretEnum(schema, model)

Interpreter function for enum keyword

interpretItems(schema, model, interpreter, interpreterOptions)

Interpreter function for items keyword.

interpretArrayItems(rootSchema, itemSchemas, model, interpreter, interpreterOptions)

Internal function to process all item schemas

interpretNot(schema, model, interpreter, interpreterOptions)

Interpreter function for not keyword.

interpretPatternProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for patternProperties keyword.

interpretProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for interpreting properties keyword.

postInterpretModel(model)

Post process the interpreted model. By applying the following:

  • Ensure models are split as required
trySplitModels(model, iteratedModels)

This function splits up a model if needed and add the new model to the list of models.

ensureModelsAreSplit(model, iteratedModels)

Split up all models which should and use ref instead.

isEnum(model)

Check if CommonModel is an enum

isModelObject(model)

Check if CommonModel is a separate model or a simple model.

inferTypeFromValue(value)

Infers the JSON Schema type from value

interpretName(schema)

Find the name for simplified version of schema

AbstractGenerator

Abstract generator which must be implemented by each language

Kind: global class

abstractGenerator.generateCompleteModels(input, options)

Generates the full output of a model, instead of a scattered model.

OutputModels result is no longer the model itself, but including package, package dependencies and model dependencies.

Kind: instance method of AbstractGenerator

Param Description
input
options to use for rendering full output

abstractGenerator.generate(input)

Generates a scattered model where dependencies and rendered results are separated.

Kind: instance method of AbstractGenerator

Param
input

abstractGenerator.processInput(input)

Process any of the input formats to the appropriate CommonInputModel type.

Kind: instance method of AbstractGenerator

Param
input

AbstractRenderer

Abstract renderer with common helper methods

Kind: global class

abstractRenderer.addDependency(dependency)

Adds a dependency while ensuring that only one dependency is preset at a time.

Kind: instance method of AbstractRenderer

Param Description
dependency complete dependency string so it can be rendered as is.

AsyncapiV2Schema

AsyncAPI schema model

Based on Draft 7 with additions

https://www.asyncapi.com/docs/specifications/v2.0.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.1.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.2.0#schemaObject https://www.asyncapi.com/docs/specifications/v2.3.0#schemaObject

Kind: global class

AsyncapiV2Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of AsyncapiV2Schema.

Kind: static method of AsyncapiV2Schema

Param
object

CommonInputModel

This class is the wrapper for simplified models and the rest of the context needed for further generate typed models.

Kind: global class

CommonModel

Common internal representation for a model.

Kind: global class

commonModel.getFromOriginalInput(key) ⇒ any

Retrieves data from originalInput by given key

Kind: instance method of CommonModel

Param Description
key given key

commonModel.setType(type)

Set the types of the model

Kind: instance method of CommonModel

Param
type

commonModel.removeType(types)

Removes type(s) from model type

Kind: instance method of CommonModel

Param
types

commonModel.addTypes(types)

Adds types to the existing model types.

Makes sure to only keep a single type incase of duplicates.

Kind: instance method of CommonModel

Param Description
types which types we should try and add to the existing output

commonModel.isRequired(propertyName) ⇒ boolean

Checks if given property name is required in object

Kind: instance method of CommonModel

Param Description
propertyName given property name

commonModel.addItem(itemModel, originalInput)

Adds an item to the model.

If items already exist the two are merged.

Kind: instance method of CommonModel

Param Description
itemModel
originalInput corresponding input that got interpreted to this model

commonModel.addItemTuple(tupleModel, originalInput, index)

Adds a tuple to the model.

If a item already exist it will be merged.

Kind: instance method of CommonModel

Param Description
tupleModel
originalInput corresponding input that got interpreted to this model
index

commonModel.addEnum(enumValue)

Add enum value to the model.

Ensures no duplicates are added.

Kind: instance method of CommonModel

Param
enumValue

commonModel.removeEnum(enumValue)

Remove enum from model.

Kind: instance method of CommonModel

Param
enumValue

commonModel.addProperty(propertyName, propertyModel, originalInput)

Adds a property to the model. If the property already exist the two are merged.

Kind: instance method of CommonModel

Param Description
propertyName
propertyModel
originalInput corresponding input that got interpreted to this model

commonModel.addAdditionalProperty(additionalPropertiesModel, originalInput)

Adds additionalProperty to the model. If another model already exist the two are merged.

Kind: instance method of CommonModel

Param Description
additionalPropertiesModel
originalInput corresponding input that got interpreted to this model corresponding input that got interpreted to this model

commonModel.addAdditionalItems(additionalItemsModel, originalInput)

Adds additionalItems to the model. If another model already exist the two are merged.

Kind: instance method of CommonModel

Param Description
additionalItemsModel
originalInput corresponding input that got interpreted to this model

commonModel.addPatternProperty(pattern, patternModel, originalInput)

Adds a patternProperty to the model. If the pattern already exist the two models are merged.

Kind: instance method of CommonModel

Param Description
pattern
patternModel
originalInput corresponding input that got interpreted to this model

commonModel.addExtendedModel(extendedModel)

Adds another model this model should extend.

It is only allowed to extend if the other model have $id and is not already being extended.

Kind: instance method of CommonModel

Param
extendedModel

commonModel.getNearestDependencies()

Returns an array of unique $ids from all the CommonModel's this model depends on.

Kind: instance method of CommonModel

CommonModel.toCommonModel(object) ⇒

Takes a deep copy of the input object and converts it to an instance of CommonModel.

Kind: static method of CommonModel
Returns: CommonModel instance of the object

Param Description
object to transform

CommonModel.mergeProperties(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Merge two common model properties together

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

CommonModel.mergeAdditionalProperties(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Merge two common model additionalProperties together

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

CommonModel.mergeAdditionalItems(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Merge two common model additionalItems together

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

CommonModel.mergePatternProperties(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Merge two common model pattern properties together

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

CommonModel.mergeItems(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Merge items together, prefer tuples over simple array since it is more strict.

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

CommonModel.mergeTypes(mergeTo, mergeFrom)

Merge types together

Kind: static method of CommonModel

Param
mergeTo
mergeFrom

CommonModel.mergeCommonModels(mergeTo, mergeFrom, originalInput, alreadyIteratedModels)

Only merge if left side is undefined and right side is sat OR both sides are defined

Kind: static method of CommonModel

Param Description
mergeTo
mergeFrom
originalInput corresponding input that got interpreted to this model
alreadyIteratedModels

Draft4Schema

JSON Draft 4 schema model

Kind: global class

Draft4Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of Draft4Schema.

Kind: static method of Draft4Schema

Param
object

Draft6Schema

JSON Draft 6 schema model

Kind: global class

Draft6Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of Draft6Schema.

Kind: static method of Draft6Schema

Param
object

Draft7Schema

JSON Draft7Schema Draft 7 model

Kind: global class

Draft7Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of Draft7Schema.

Kind: static method of Draft7Schema

Param
object

OpenapiV3Schema

OpenAPI 3.0 -> 3.0.4 schema model

Based on Draft 6, but with restricted keywords and definitions Modifications

  • type, cannot be an array nor contain 'null'

Restrictions (keywords not allowed)

  • patternProperties
  • not

https://swagger.io/specification/#schema-object

Kind: global class

OpenapiV3Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of OpenapiV3Schema.

Kind: static method of OpenapiV3Schema

Param
object

OutputModel

Common representation for the output model.

Kind: global class

RenderOutput

Common representation for the rendered output.

Kind: global class

SwaggerV2Schema

OpenAPI 2.0 (Swagger 2.0) schema model

Based on Draft 4, but with restricted keywords and definitions

Restrictions (keywords not allowed)

  • oneOf
  • anyOf
  • patternProperties
  • not

https://swagger.io/specification/v2/#schemaObject

Kind: global class

SwaggerV2Schema.toSchema(object)

Takes a deep copy of the input object and converts it to an instance of SwaggerV2Schema.

Kind: static method of SwaggerV2Schema

Param
object

AsyncAPIInputProcessor

Class for processing AsyncAPI inputs

Kind: global class

asyncAPIInputProcessor.process(input)

Process the input as an AsyncAPI document

Kind: instance method of AsyncAPIInputProcessor

Param
input

asyncAPIInputProcessor.shouldProcess(input)

Figures out if an object is of type AsyncAPI document

Kind: instance method of AsyncAPIInputProcessor

Param
input

asyncAPIInputProcessor.tryGetVersionOfDocument(input)

Try to find the AsyncAPI version from the input. If it cannot undefined are returned, if it can, the version is returned.

Kind: instance method of AsyncAPIInputProcessor

Param
input

AsyncAPIInputProcessor.convertToInternalSchema(schema)

Reflect the name of the schema and save it to x-modelgen-inferred-name extension.

This keeps the the id of the model deterministic if used in conjunction with other AsyncAPI tools such as the generator.

Kind: static method of AsyncAPIInputProcessor

Param Description
schema to reflect name for

AsyncAPIInputProcessor.isFromParser(input)

Figure out if input is from the AsyncAPI js parser.

Kind: static method of AsyncAPIInputProcessor

Param
input

InputProcessor

Main input processor which figures out the type of input it receives and delegates the processing into separate individual processors.

Kind: global class

inputProcessor.setProcessor(type, processor)

Set a processor.

Kind: instance method of InputProcessor

Param Description
type of processor
processor

inputProcessor.getProcessors() ⇒

Kind: instance method of InputProcessor
Returns: all processors

inputProcessor.process(input, options)

The processor code which delegates the processing to the correct implementation.

Kind: instance method of InputProcessor

Param Description
input to process
options passed to the processors

JsonSchemaInputProcessor

Class for processing JSON Schema

Kind: global class

jsonSchemaInputProcessor.process(input)

Function for processing a JSON Schema input.

Kind: instance method of JsonSchemaInputProcessor

Param
input

jsonSchemaInputProcessor.shouldProcess(input)

Unless the schema states one that is not supported we assume its of type JSON Schema

Kind: instance method of JsonSchemaInputProcessor

Param
input

jsonSchemaInputProcessor.processDraft7(input)

Process a draft-7 schema

Kind: instance method of JsonSchemaInputProcessor

Param Description
input to process as draft 7

jsonSchemaInputProcessor.processDraft4(input)

Process a draft-4 schema

Kind: instance method of JsonSchemaInputProcessor

Param Description
input to process as draft 4

jsonSchemaInputProcessor.processDraft6(input)

Process a draft-6 schema

Kind: instance method of JsonSchemaInputProcessor

Param Description
input to process as draft-6

JsonSchemaInputProcessor.reflectSchemaNames(schema, namesStack, name, isRoot)

Each schema must have a name, so when later interpreted, the model have the most accurate model name.

Reflect name from given schema and save it to x-modelgen-inferred-name extension.

This reflects all the common keywords that are shared between draft-4, draft-7 and Swagger 2.0 Schema

Kind: static method of JsonSchemaInputProcessor

Param Description
schema to process
namesStack is a aggegator of previous used names
name to infer
isRoot indicates if performed schema is a root schema

JsonSchemaInputProcessor.ensureNamePattern(previousName, ...newParts)

Ensure schema name using previous name and new part

Kind: static method of JsonSchemaInputProcessor

Param Description
previousName to concatenate with
...newParts

JsonSchemaInputProcessor.convertSchemaToCommonModel(schema)

Simplifies a JSON Schema into a common models

Kind: static method of JsonSchemaInputProcessor

Param Description
schema to simplify to common model

OpenAPIInputProcessor

Class for processing OpenAPI V3.0 inputs

Kind: global class

openAPIInputProcessor.process(input)

Process the input as a OpenAPI V3.0 document

Kind: instance method of OpenAPIInputProcessor

Param
input

openAPIInputProcessor.shouldProcess(input)

Figures out if an object is of type OpenAPI V3.0.x document and supported

Kind: instance method of OpenAPIInputProcessor

Param
input

openAPIInputProcessor.tryGetVersionOfDocument(input)

Try to find the AsyncAPI version from the input. If it cannot undefined are returned, if it can, the version is returned.

Kind: instance method of OpenAPIInputProcessor

Param
input

OpenAPIInputProcessor.convertToInternalSchema(schema, name)

Converts a schema to the internal schema format.

Kind: static method of OpenAPIInputProcessor

Param Description
schema to convert
name of the schema

SwaggerInputProcessor

Class for processing Swagger inputs

Kind: global class

swaggerInputProcessor.process(input)

Process the input as a Swagger document

Kind: instance method of SwaggerInputProcessor

Param
input

swaggerInputProcessor.shouldProcess(input)

Figures out if an object is of type Swagger document and supported

Kind: instance method of SwaggerInputProcessor

Param
input

swaggerInputProcessor.tryGetVersionOfDocument(input)

Try to find the swagger version from the input. If it cannot, undefined are returned, if it can, the version is returned.

Kind: instance method of SwaggerInputProcessor

Param
input

SwaggerInputProcessor.convertToInternalSchema(schema, name)

Converts a Swagger 2.0 Schema to the internal schema format.

Kind: static method of SwaggerInputProcessor

Param Description
schema to convert
name of the schema

LoggerClass

Logger class for the model generation library

This class acts as a forefront for any external loggers which is why it also implements the interface itself.

Kind: global class

loggerClass.setLogger(logger)

Sets the logger to use for the model generation library

Kind: instance method of LoggerClass

Param Description
logger to add

DefaultPropertyNames

Default property names for different aspects of the common model

Kind: global variable

CommonNamingConventionImplementation

A CommonNamingConvention implementation shared between generators for different languages.

Kind: global variable

getUniquePropertyName(rootModel, propertyName)

Recursively find the proper property name.

This function ensures that the property name is unique for the model

Kind: global function

Param
rootModel
propertyName

hasPreset(presets, preset)

Returns true if and only if a given preset is already included in a list of presets Check is done using referential equality

Kind: global function

Param Description
presets the list to check
preset the preset to check for

interpretAdditionalItems(schema, model, interpreter, interpreterOptions)

Interpreter function for additionalItems keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretAdditionalProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for additionalProperties keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretAllOf(schema, model, interpreter, interpreterOptions)

Interpreter function for allOf keyword.

It either merges allOf schemas into existing model or if allowed, create inheritance.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretConst(schema, model)

Interpreter function for const keyword for draft version > 4

Kind: global function

Param
schema
model

interpretDependencies(schema, model)

Interpreter function for dependencies keyword.

Kind: global function

Param
schema
model

interpretEnum(schema, model)

Interpreter function for enum keyword

Kind: global function

Param
schema
model

interpretItems(schema, model, interpreter, interpreterOptions)

Interpreter function for items keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretArrayItems(rootSchema, itemSchemas, model, interpreter, interpreterOptions)

Internal function to process all item schemas

Kind: global function

Param Description
rootSchema
itemSchemas
model
interpreter
interpreterOptions to control the interpret process

interpretNot(schema, model, interpreter, interpreterOptions)

Interpreter function for not keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretPatternProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for patternProperties keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

interpretProperties(schema, model, interpreter, interpreterOptions)

Interpreter function for interpreting properties keyword.

Kind: global function

Param Description
schema
model
interpreter
interpreterOptions to control the interpret process

postInterpretModel(model)

Post process the interpreted model. By applying the following:

  • Ensure models are split as required

Kind: global function

Param
model

trySplitModels(model, iteratedModels)

This function splits up a model if needed and add the new model to the list of models.

Kind: global function

Param Description
model check if it should be split up
iteratedModels which have already been split up

ensureModelsAreSplit(model, iteratedModels)

Split up all models which should and use ref instead.

Kind: global function

Param Description
model to ensure are split
iteratedModels which are already split

isEnum(model)

Check if CommonModel is an enum

Kind: global function

Param
model

isModelObject(model)

Check if CommonModel is a separate model or a simple model.

Kind: global function

Param
model

inferTypeFromValue(value)

Infers the JSON Schema type from value

Kind: global function

Param Description
value to infer type of

interpretName(schema)

Find the name for simplified version of schema

Kind: global function

Param Description
schema to find the name