public class SwaggerAvroModelConverter
extends com.wordnik.swagger.converter.SwaggerSchemaConverter
This will only attempt to process classes which derive from
SpecificRecordBase
and contain a static field named SCHEMA$
which is an instance of Schema
. The default Avro code generator for Java
produces such classes. If you need to handle other classes, override getSchema(Class)
.
All of the following are currently unsupported and will result in omitted fields:
array<array<string>>
are unsupported, you can of
course have a collection inside a record inside a collectionUnions of 'null' and one other type will be treated as optional fields; all other fields will be assumed required.
Avro fields of type 'bytes' are represented as Swagger properties of type 'string', format 'byte'.
By default, field names are converted to snake case. You can override the
getFieldName(Schema.Field)
method to change this.
To accommodate javadoc-style comments in avdl files, by default, if a line of a model/field
description begins with whitespace followed by an asterisk, those characters (along with one
subsequent whitespace character) will be removed. You can override the
adjustDescription(String)
method to change this.
Constructor and Description |
---|
SwaggerAvroModelConverter() |
Modifier and Type | Method and Description |
---|---|
protected String |
adjustDescription(String doc)
Given the doc string for an Avro entity, return the Swagger description to use.
|
protected String |
getFieldName(org.apache.avro.Schema.Field field)
Given an Avro field, return the name that should be used for the Swagger property.
|
protected String |
getName(org.apache.avro.Schema schema) |
protected org.apache.avro.Schema |
getSchema(Class<?> cls)
Return the Avro schema for the given class, or null if this converter should not handle this
class.
|
protected com.wordnik.swagger.model.ModelProperty |
parseField(org.apache.avro.Schema.Field field)
Generate a ModelProperty for the given field.
|
protected com.wordnik.swagger.model.ModelProperty |
parseSchema(org.apache.avro.Schema schema)
Generate a ModelProperty for the given schema.
|
scala.Option<com.wordnik.swagger.model.Model> |
read(Class<?> cls,
scala.collection.immutable.Map<String,String> typeMap) |
scala.Option<String> |
toDescriptionOpt(Class<?> cls) |
String |
toName(Class<?> cls) |
public scala.Option<com.wordnik.swagger.model.Model> read(Class<?> cls, scala.collection.immutable.Map<String,String> typeMap)
read
in interface com.wordnik.swagger.converter.ModelConverter
read
in class com.wordnik.swagger.converter.SwaggerSchemaConverter
public String toName(Class<?> cls)
toName
in interface com.wordnik.swagger.converter.BaseConverter
toName
in interface com.wordnik.swagger.converter.ModelConverter
toName
in class com.wordnik.swagger.converter.SwaggerSchemaConverter
public scala.Option<String> toDescriptionOpt(Class<?> cls)
toDescriptionOpt
in interface com.wordnik.swagger.converter.BaseConverter
toDescriptionOpt
in interface com.wordnik.swagger.converter.ModelConverter
toDescriptionOpt
in class com.wordnik.swagger.converter.SwaggerSchemaConverter
protected String getName(org.apache.avro.Schema schema)
@Nullable protected com.wordnik.swagger.model.ModelProperty parseSchema(org.apache.avro.Schema schema)
This is used by parseField(Schema.Field)
, which is responsible for
overriding the parts of the ModelProperty (such as position and description) that cannot be
determined merely by looking at the schema. It may also be used recursively to build collection
and union types.
@Nullable protected com.wordnik.swagger.model.ModelProperty parseField(org.apache.avro.Schema.Field field)
@Nullable protected org.apache.avro.Schema getSchema(Class<?> cls)
protected String getFieldName(org.apache.avro.Schema.Field field)
Copyright © 2020 Cerner Innovation, Inc.. All rights reserved.