Skip to content

Commit

Permalink
refs swagger-api#2277 - add json ignored 'name'to schema
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jul 19, 2017
1 parent 023c99e commit 051b4a5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.ObjectIdGenerator;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
Expand All @@ -29,10 +28,8 @@
import io.swagger.oas.models.media.Schema;
import io.swagger.oas.models.media.StringSchema;
import io.swagger.oas.models.media.UUIDSchema;
import io.swagger.util.Json;
import io.swagger.util.PrimitiveType;
import io.swagger.util.ReflectionUtils;
import io.swagger.util.Yaml;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -259,12 +256,12 @@ else if(PrimitiveType.fromType(type) != null) {
if (isComposedSchema) {
model = new ComposedSchema()
.type("object")
.title(name)
.name(name)
.description(_description(beanDesc.getClassInfo()));
} else {
model = new Schema()
.type("object")
.title(name)
.name(name)
.description(_description(beanDesc.getClassInfo()));
}

Expand Down Expand Up @@ -599,7 +596,7 @@ else if(PrimitiveType.fromType(type) != null) {
if (schemaAnnotation != null) {
Class<?> not = schemaAnnotation.not();
if (!Void.class.equals(not)) {
model.not((new Schema().$ref(context.resolve(not.getClass()).getTitle())));
model.not((new Schema().$ref(context.resolve(not.getClass()).getName())));
}
}

Expand All @@ -622,7 +619,7 @@ else if(PrimitiveType.fromType(type) != null) {
.collect(Collectors.toList());
allOfFiltered.forEach(c -> {
Schema allOfRef = context.resolve(c);
composedSchema.addAllOfItem(new Schema().$ref(allOfRef.getTitle()));
composedSchema.addAllOfItem(new Schema().$ref(allOfRef.getName()));
final Map<String, Schema> baseProps = allOfRef.getProperties();
final Map<String, Schema> subtypeProps = composedSchema.getProperties();
if (baseProps != null && subtypeProps != null) {
Expand All @@ -647,7 +644,7 @@ else if(PrimitiveType.fromType(type) != null) {
// TODO do we want to expand this? or use ref? and remove interface schema??
// or do we want to only "resolve" interfaces, and not classes in anyOf?
// TODO do we want to implement the same for allOf and oneOf?
//composedSchema.addAnyOfItem(new Schema().$ref(anyOfRef.getTitle()));
//composedSchema.addAnyOfItem(new Schema().$ref(anyOfRef.getName()));
composedSchema.addAnyOfItem(anyOfRef);
// remove shared properties defined in the parent
final Map<String, Schema> baseProps = anyOfRef.getProperties();
Expand All @@ -670,7 +667,7 @@ else if(PrimitiveType.fromType(type) != null) {
.filter(c -> !this.shouldIgnoreClass(c))
.filter(c -> !(c.equals(Void.class)))
.collect(Collectors.toList());
oneOfFiltered.forEach(c -> composedSchema.addOneOfItem(new Schema().$ref(context.resolve(c).getTitle())));
oneOfFiltered.forEach(c -> composedSchema.addOneOfItem(new Schema().$ref(context.resolve(c).getName())));


/* TODO do we need logic below (from 2.0)? do we need the "child" to be referenced by the "parent" to be resolved?
Expand Down Expand Up @@ -984,8 +981,8 @@ private boolean resolveSubtypes(Schema model, BeanDescription bean, ModelConvert

final Schema subtypeModel = context.resolve(subtypeType);

if (subtypeModel.getTitle().equals(model.getTitle())) {
subtypeModel.setTitle(_typeNameResolver.nameForType(_mapper.constructType(subtypeType),
if (subtypeModel.getName().equals(model.getName())) {
subtypeModel.setName(_typeNameResolver.nameForType(_mapper.constructType(subtypeType),
TypeNameResolver.Options.SKIP_API_MODEL));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.swagger.oas.models.media;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.oas.models.ExternalDocumentation;

import java.math.BigDecimal;
Expand All @@ -36,6 +37,7 @@
public class Schema<T> {
protected T _default;

private String name;
private String title = null;
private BigDecimal multipleOf = null;
private BigDecimal maximum = null;
Expand Down Expand Up @@ -69,6 +71,25 @@ public class Schema<T> {
protected List<T> _enum = null;
private Discriminator discriminator = null;

/**
* returns the name property from a from a Schema instance. Ignored in serialization.
*
* @return String name
**/
@JsonIgnore
public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public Schema name(String name) {
this.setName(name);
return this;
}

/**
* returns the discriminator property from a AllOfSchema instance.
*
Expand Down

0 comments on commit 051b4a5

Please sign in to comment.