Skip to content
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

[#195] Implement Discriminator object #205

Merged
merged 1 commit into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.reprezen.kaizen.oasparser.model3;

import java.util.Map;

import javax.annotation.Generated;

import com.reprezen.jsonoverlay.IJsonOverlay;
import com.reprezen.jsonoverlay.IModelPart;

public interface Discriminator extends IJsonOverlay<Discriminator>, IModelPart<OpenApi3, Discriminator> {

// PropertyName
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
String getPropertyName();

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void setPropertyName(String propertyName);

// Mapping
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
Map<String, String> getMappings();

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
Map<String, String> getMappings(boolean elaborate);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
boolean hasMappings();

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
boolean hasMapping(String name);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
String getMapping(String name);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void setMappings(Map<String, String> mappings);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void setMapping(String name, String mapping);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void removeMapping(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,13 @@ public interface Schema extends IJsonOverlay<Schema>, IModelPart<OpenApi3, Schem

// Discriminator
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
String getDiscriminator();
Discriminator getDiscriminator();

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void setDiscriminator(String discriminator);
Discriminator getDiscriminator(boolean elaborate);

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
void setDiscriminator(Discriminator discriminator);

// ReadOnly
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
package com.reprezen.kaizen.oasparser.ovl3;

import java.util.Map;

import javax.annotation.Generated;

import com.fasterxml.jackson.databind.JsonNode;
import com.reprezen.jsonoverlay.JsonOverlay;
import com.reprezen.jsonoverlay.OverlayFactory;
import com.reprezen.jsonoverlay.PropertiesOverlay;
import com.reprezen.jsonoverlay.ReferenceManager;
import com.reprezen.jsonoverlay.StringOverlay;
import com.reprezen.kaizen.oasparser.model3.Discriminator;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;

public class DiscriminatorImpl extends PropertiesOverlay<Discriminator> implements Discriminator {

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public DiscriminatorImpl(JsonNode json, JsonOverlay<?> parent, ReferenceManager refMgr) {
super(json, parent, factory, refMgr);
}

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public DiscriminatorImpl(Discriminator discriminator, JsonOverlay<?> parent, ReferenceManager refMgr) {
super(discriminator, parent, factory, refMgr);
}

// PropertyName
@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public String getPropertyName() {
return _get("propertyName", String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void setPropertyName(String propertyName) {
_setScalar("propertyName", propertyName, String.class);
}

// Mapping
@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public Map<String, String> getMappings() {
return _getMap("mappings", String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public Map<String, String> getMappings(boolean elaborate) {
return _getMap("mappings", elaborate, String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public boolean hasMappings() {
return _isPresent("mappings");
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public boolean hasMapping(String name) {
return _getMap("mappings", String.class).containsKey(name);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public String getMapping(String name) {
return _get("mappings", name, String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void setMappings(Map<String, String> mappings) {
_setMap("mappings", mappings, String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void setMapping(String name, String mapping) {
_set("mappings", name, mapping, String.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void removeMapping(String name) {
_remove("mappings", name, String.class);
}

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public static final String F_propertyName = "propertyName";

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public static final String F_mappings = "mappings";

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
protected void _elaborateJson() {
super._elaborateJson();
_createScalar("propertyName", "propertyName", StringOverlay.factory);
_createMap("mappings", "mapping", StringOverlay.factory, null);
}

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public static OverlayFactory<Discriminator> factory = new OverlayFactory<Discriminator>() {

@Override
protected Class<? extends JsonOverlay<? super Discriminator>> getOverlayClass() {
return DiscriminatorImpl.class;
}

@Override
public JsonOverlay<Discriminator> _create(Discriminator discriminator, JsonOverlay<?> parent,
ReferenceManager refMgr) {
JsonOverlay<?> overlay;
overlay = new DiscriminatorImpl(discriminator, parent, refMgr);
@SuppressWarnings("unchecked")
JsonOverlay<Discriminator> castOverlay = (JsonOverlay<Discriminator>) overlay;
return castOverlay;
}

@Override
public JsonOverlay<Discriminator> _create(JsonNode json, JsonOverlay<?> parent, ReferenceManager refMgr) {
JsonOverlay<?> overlay;
overlay = new DiscriminatorImpl(json, parent, refMgr);
@SuppressWarnings("unchecked")
JsonOverlay<Discriminator> castOverlay = (JsonOverlay<Discriminator>) overlay;
return castOverlay;
}

@Override
protected boolean isExtendedType() {
return false;
}
};

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
private static Class<? extends Discriminator> getSubtypeOf(Discriminator discriminator) {
return Discriminator.class;
}

@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
private static Class<? extends Discriminator> getSubtypeOf(JsonNode json) {
return Discriminator.class;
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public Class<?> _getModelType() {
return OpenApi3.class;
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
protected OverlayFactory<?> _getFactory() {
return factory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.reprezen.jsonoverlay.PropertiesOverlay;
import com.reprezen.jsonoverlay.ReferenceManager;
import com.reprezen.jsonoverlay.StringOverlay;
import com.reprezen.kaizen.oasparser.model3.Discriminator;
import com.reprezen.kaizen.oasparser.model3.ExternalDocs;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.reprezen.kaizen.oasparser.model3.Schema;
Expand Down Expand Up @@ -731,14 +732,20 @@ public void setNullable(Boolean nullable) {
// Discriminator
@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public String getDiscriminator() {
return _get("discriminator", String.class);
public Discriminator getDiscriminator() {
return _get("discriminator", Discriminator.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void setDiscriminator(String discriminator) {
_setScalar("discriminator", discriminator, String.class);
public Discriminator getDiscriminator(boolean elaborate) {
return _get("discriminator", elaborate, Discriminator.class);
}

@Override
@Generated("com.reprezen.jsonoverlay.gen.CodeGenerator")
public void setDiscriminator(Discriminator discriminator) {
_setScalar("discriminator", discriminator, Discriminator.class);
}

// ReadOnly
Expand Down Expand Up @@ -1045,7 +1052,7 @@ protected void _elaborateJson() {
_createScalar("format", "format", StringOverlay.factory);
_createScalar("defaultValue", "default", ObjectOverlay.factory);
_createScalar("nullable", "nullable", BooleanOverlay.factory);
_createScalar("discriminator", "discriminator", StringOverlay.factory);
_createScalar("discriminator", "discriminator", DiscriminatorImpl.factory);
_createScalar("readOnly", "readOnly", BooleanOverlay.factory);
_createScalar("writeOnly", "writeOnly", BooleanOverlay.factory);
_createScalar("xml", "xml", XmlImpl.factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,27 +427,30 @@ types:
imports:
impl:
- Overlay
fields: &headerFields
description: {}
required:
fields:
description: &id012 {
}
required: &id011
type: Boolean
deprecated:
deprecated: &id010
type: Boolean
allowEmptyValue:
allowEmptyValue: &id009
type: Boolean
style: {}
explode:
style: &id008 {
}
explode: &id007
type: Boolean
allowReserved:
allowReserved: &id006
type: Boolean
schema: {}
example:
schema: &id005 {
}
example: &id004
type: Object
examples:
examples: &id003
type: Example
structure: map
keyPattern: '[a-zA-Z0-9\._-]+'
content:
content: &id002
name: ContentMediaType
type: MediaType
structure: map
Expand All @@ -457,11 +460,22 @@ types:
impl:
- Overlay
fields:
in: {
}
extension: *id001
content: *id002
examples: *id003
example: *id004
schema: *id005
allowReserved: *id006
explode: *id007
style: *id008
allowEmptyValue: *id009
deprecated: *id010
required: *id011
description: *id012
name: {
}
<<: *headerFields
in: {
}
- name: Schema
imports:
impl:
Expand Down Expand Up @@ -584,4 +598,11 @@ types:
type: Object
externalValue: {
}
extension: *id001
extension: *id001
- name: Discriminator
fields:
propertyName: {
}
mapping:
type: String
structure: map
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public final <F> Overlay<F> validateField(String name, boolean required, Class<F
Overlay<F> field = Overlay.of(propValue, name, fieldClass);
checkJsonType(field, getAllowedJsonTypes(field), results);
checkMissing(field, required);
if (value != null && value.isPresent() && validator != null) {
if (field != null && field.isPresent() && validator != null) {
validator.validate(field);
for (Consumer<Overlay<F>> otherCheck : otherChecks) {
otherCheck.accept(field);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.reprezen.kaizen.oasparser.val3;

import com.reprezen.kaizen.oasparser.model3.Discriminator;
import com.reprezen.kaizen.oasparser.ovl3.DiscriminatorImpl;
import com.reprezen.kaizen.oasparser.val.ValidatorBase;

public class DiscriminatorValidator extends ValidatorBase<Discriminator> {

@Override
public void runValidations() {
validateStringField(DiscriminatorImpl.F_propertyName, true);
validateMapField("mappings", false, false, String.class, null);
}
}
Loading