This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #444 Validation fails when using uses inside a DataType fragmen…
…t. (#445) * Fixes #444 Validation fails when using uses inside a DataType fragment. * Code review changes. * Full qualified name removed.
- Loading branch information
1 parent
2b536aa
commit 23623e3
Showing
13 changed files
with
211 additions
and
78 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
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
69 changes: 69 additions & 0 deletions
69
...-2/src/main/java/org/raml/v2/internal/impl/commons/nodes/TypeDeclarationNodeFragment.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,69 @@ | ||
/* | ||
* Copyright 2013 (c) MuleSoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
package org.raml.v2.internal.impl.commons.nodes; | ||
|
||
import org.raml.v2.api.model.v10.RamlFragment; | ||
import org.raml.v2.internal.impl.commons.phase.RamlTypedFragment; | ||
import org.raml.v2.internal.impl.v10.grammar.Raml10Grammar; | ||
import org.raml.yagi.framework.nodes.Node; | ||
import org.raml.yagi.framework.util.NodeSelector; | ||
import org.raml.yagi.framework.util.NodeUtils; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import static org.raml.v2.api.model.v10.RamlFragment.DataType; | ||
|
||
|
||
public class TypeDeclarationNodeFragment extends TypeDeclarationNode implements RamlTypedFragment | ||
{ | ||
|
||
private Node libraryNode; | ||
|
||
@Nonnull | ||
@Override | ||
public Node getContextNode() | ||
{ | ||
return getLibraryNode() != null || getParent() == null ? this : NodeUtils.getContextNode(getParent()); | ||
} | ||
|
||
@Override | ||
public Node getLibraryNode() | ||
{ | ||
if (libraryNode == null) | ||
{ | ||
libraryNode = NodeSelector.selectFrom(Raml10Grammar.USES_KEY_NAME, this); | ||
} | ||
return libraryNode; | ||
} | ||
|
||
public void | ||
resolveLibraryReference() | ||
{ | ||
libraryNode = NodeSelector.selectFrom(Raml10Grammar.USES_KEY_NAME, this); | ||
if (libraryNode != null) | ||
{ | ||
// The parent is the key value pair | ||
final Node parent = libraryNode.getParent(); | ||
removeChild(parent); | ||
} | ||
} | ||
|
||
@Override | ||
public RamlFragment getFragment() | ||
{ | ||
return DataType; | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...n/java/org/raml/v2/internal/impl/commons/phase/RamlFragmentLibraryLinkingTransformer.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,59 @@ | ||
/* | ||
* Copyright 2013 (c) MuleSoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
package org.raml.v2.internal.impl.commons.phase; | ||
|
||
import org.raml.v2.api.loader.ResourceLoader; | ||
import org.raml.v2.internal.impl.v10.Raml10Builder; | ||
import org.raml.v2.internal.impl.v10.phase.LibraryLinkingTransformation; | ||
import org.raml.v2.internal.impl.v10.phase.ReferenceResolverTransformer; | ||
import org.raml.yagi.framework.nodes.Node; | ||
import org.raml.yagi.framework.phase.TransformationPhase; | ||
import org.raml.yagi.framework.phase.Transformer; | ||
|
||
import static org.raml.v2.internal.utils.PhaseUtils.applyPhases; | ||
|
||
public class RamlFragmentLibraryLinkingTransformer implements Transformer | ||
{ | ||
|
||
private final Raml10Builder builder; | ||
private final ResourceLoader resourceLoader; | ||
|
||
public RamlFragmentLibraryLinkingTransformer(Raml10Builder builder, ResourceLoader resourceLoader) | ||
{ | ||
this.builder = builder; | ||
this.resourceLoader = resourceLoader; | ||
} | ||
|
||
@Override | ||
public boolean matches(Node node) | ||
{ | ||
return node instanceof RamlTypedFragment && node.getParent() != null; | ||
} | ||
|
||
@Override | ||
public Node transform(Node node) | ||
{ | ||
Node apply = applyPhases(node, new TransformationPhase(new LibraryLinkingTransformation(builder, resourceLoader))); | ||
|
||
if (apply instanceof RamlTypedFragment) | ||
{ | ||
// Hack!!!! | ||
((RamlTypedFragment) apply).resolveLibraryReference(); | ||
} | ||
apply = applyPhases(apply, new TransformationPhase(new ReferenceResolverTransformer())); | ||
return apply; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
raml-parser-2/src/main/java/org/raml/v2/internal/impl/commons/phase/RamlTypedFragment.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,25 @@ | ||
/* | ||
* Copyright 2013 (c) MuleSoft, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, | ||
* either express or implied. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
*/ | ||
package org.raml.v2.internal.impl.commons.phase; | ||
|
||
import org.raml.v2.api.model.v10.RamlFragment; | ||
import org.raml.v2.internal.impl.commons.nodes.LibraryNodeProvider; | ||
import org.raml.yagi.framework.nodes.ContextProviderNode; | ||
|
||
public interface RamlTypedFragment extends LibraryNodeProvider, ContextProviderNode | ||
{ | ||
RamlFragment getFragment(); | ||
} |
Oops, something went wrong.