-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#195] Implement Discriminator object
Includes update to model types file, regeneration of classes, creation of new DiscriminatorValidator, and update to SchemaValidator. Also, fixed a bug in ValidatorBase - wrong overlay value was being checked by the apssed validator in validateField method! Once we have checks for unrecognized properties, that will be far more visible. (And of course we should get validator tests!)
- Loading branch information
Showing
9 changed files
with
276 additions
and
40 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
kaizen-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/model3/Discriminator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
...en-openapi-parser/src/main/java/com/reprezen/kaizen/oasparser/ovl3/DiscriminatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...enapi-parser/src/main/java/com/reprezen/kaizen/oasparser/val3/DiscriminatorValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.