-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a feature to allow traits to "shade" entity properties. This wi…
…ll make it easier to create custom traits and still maintain property ordering
- Loading branch information
1 parent
7fba1c9
commit 875a1d3
Showing
19 changed files
with
490 additions
and
10 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -16,16 +16,13 @@ | |
|
||
package io.apicurio.umg; | ||
|
||
import java.util.Collection; | ||
|
||
import io.apicurio.umg.logging.Logger; | ||
import io.apicurio.umg.models.spec.SpecificationModel; | ||
import io.apicurio.umg.pipe.GeneratorState; | ||
import io.apicurio.umg.pipe.Pipeline; | ||
import io.apicurio.umg.pipe.concept.CreateEntityModelsStage; | ||
import io.apicurio.umg.pipe.concept.CreateImplicitUnionRulesStage; | ||
import io.apicurio.umg.pipe.concept.CreateNamespaceModelsStage; | ||
import io.apicurio.umg.pipe.concept.CreateParentTraitsStage; | ||
import io.apicurio.umg.pipe.concept.CreatePropertyComparatorStage; | ||
import io.apicurio.umg.pipe.concept.CreatePropertyModelsStage; | ||
import io.apicurio.umg.pipe.concept.CreateTraitModelsStage; | ||
|
@@ -36,6 +33,7 @@ | |
import io.apicurio.umg.pipe.concept.NormalizePropertiesStage; | ||
import io.apicurio.umg.pipe.concept.NormalizeTraitsStage; | ||
import io.apicurio.umg.pipe.concept.NormalizeVisitorsStage; | ||
import io.apicurio.umg.pipe.concept.RemoveShadedPropertyModelsStage; | ||
import io.apicurio.umg.pipe.concept.RemoveTransparentTraitsStage; | ||
import io.apicurio.umg.pipe.concept.ResolveVisitorEntityStage; | ||
import io.apicurio.umg.pipe.concept.SpecificationValidationStage; | ||
|
@@ -71,6 +69,8 @@ | |
import io.apicurio.umg.pipe.java.OrganizeImportsStage; | ||
import io.apicurio.umg.pipe.java.RemoveUnusedImportsStage; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* @author [email protected] | ||
*/ | ||
|
@@ -110,9 +110,10 @@ public void generate() throws Exception { | |
pipe.addStage(new CreateNamespaceModelsStage()); | ||
pipe.addStage(new CreateTraitModelsStage()); | ||
pipe.addStage(new CreateEntityModelsStage()); | ||
// pipe.addStage(new CreateParentTraitsStage()); | ||
pipe.addStage(new CreatePropertyModelsStage()); | ||
pipe.addStage(new CreateParentTraitsStage()); | ||
pipe.addStage(new CreateVisitorsStage()); | ||
pipe.addStage(new RemoveShadedPropertyModelsStage()); | ||
|
||
// Implicit model creation phase | ||
pipe.addStage(new CreateImplicitUnionRulesStage()); | ||
|
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
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
32 changes: 32 additions & 0 deletions
32
generator/src/main/java/io/apicurio/umg/pipe/concept/RemoveShadedPropertyModelsStage.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,32 @@ | ||
package io.apicurio.umg.pipe.concept; | ||
|
||
import io.apicurio.umg.models.concept.PropertyModel; | ||
import io.apicurio.umg.pipe.AbstractStage; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Removes any shaded property models from their entities. A shaded property is one | ||
* that is defined on an Entity but *also* defined on a Trait of that Entity. This | ||
* is redundant and only supported to make property ordering easier in the spec | ||
* definitions (this allows you to define a property in both a Trait and an Entity - | ||
* only the Trait property will be used when generating code, but the property in the | ||
* Entity will be used for ordering). | ||
*/ | ||
public class RemoveShadedPropertyModelsStage extends AbstractStage { | ||
|
||
@Override | ||
protected void doProcess() { | ||
info("-- Removing shaded Entity properties --"); | ||
getState().getConceptIndex().getAllEntitiesWithCopy().forEach(entity -> { | ||
Set<String> propertyNames = Set.copyOf(entity.getProperties().keySet()); | ||
for (String propertyName : propertyNames) { | ||
PropertyModel propertyModel = entity.getProperties().get(propertyName); | ||
if (propertyModel.isShaded()) { | ||
entity.getProperties().remove(propertyName); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
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
67 changes: 67 additions & 0 deletions
67
generator/src/test/resources/io/apicurio/umg/parent-trait-spec-v1.yaml
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,67 @@ | ||
name: Parent Trait Test API 1.0 | ||
version: 1.0 | ||
versions: | ||
- version: 1.0 | ||
url: https://example.com/ParentTrait/versions/1.0.md | ||
prefix: Pt10 | ||
namespace: io.apicurio.umg.test.v10 | ||
|
||
traits: | ||
- name: FooParent | ||
properties: | ||
- name: foo | ||
type: Foo | ||
|
||
entities: | ||
- name: Document | ||
root: true | ||
traits: | ||
- FooParent | ||
properties: | ||
- name: id | ||
type: string | ||
- name: foo | ||
type: Foo | ||
- name: bar | ||
type: Bar | ||
- name: definitions | ||
type: Definitions | ||
propertyOrder: | ||
- $this | ||
|
||
- name: Foo | ||
properties: | ||
- name: name | ||
type: string | ||
- name: description | ||
type: string | ||
propertyOrder: | ||
- $this | ||
|
||
- name: Bar | ||
properties: | ||
- name: type | ||
type: string | ||
- name: color | ||
type: string | ||
propertyOrder: | ||
- $this | ||
|
||
- name: Baz | ||
properties: | ||
- name: length | ||
type: number | ||
propertyOrder: | ||
- $this | ||
|
||
- name: Definitions | ||
traits: | ||
- FooParent | ||
properties: | ||
- name: foo | ||
type: Foo | ||
- name: baz | ||
type: Baz | ||
propertyOrder: | ||
- $this | ||
|
Oops, something went wrong.