-
Notifications
You must be signed in to change notification settings - Fork 12
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
#227 Better code completion proposal for name/key of additional properties #402
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9b18047
#227 - use schema name for code-assist for additionalProperties
tfesenko e839fab
#227 - code assist: select the schema name for the additionalProperti…
tfesenko e027674
Fix compilation errors in tests
tfesenko 522b4b3
#227 - generate named schema templates from inline schema templates
tfesenko 1bc87dc
Merge branch 'master' into task/227
tfesenko 833d212
#227 - clean up code for the 'additionalProperties' code assist, cust…
tfesenko 9194da2
Manually merge master into task/227
tfesenko 1a46dc0
Manually merge master into task/227
tfesenko a3e7351
#227 - use '(schema name)' as a proposal for the elements described b…
tfesenko 6360421
#227 - fix reference type provider for cases when a reference node al…
tfesenko fd8c537
#227 - fix test failures in CodeTemplateTextTest (named schema templa…
tfesenko 2ee8900
#227 - add dynamic code templates for named schema properties + tests
tfesenko 7da4404
#227 - code templates for named schemas should create schema names in…
tfesenko 4e80a49
#227 - restore cursor position for empty selection - it should be at …
tfesenko b6d8378
#227 - tests for code assist for component keys
tfesenko a62a95a
#227 - more tests for code assist for the additionalProperties elements
tfesenko e43d350
#227 - make getTabWidth() reusable
tfesenko 3931b3c
#227 - remove unneeded JSON Schema customizations
tfesenko 648042a
#227 - Fix code assist proposal for named schema properties in Swagge…
tfesenko 919d64d
#227 - regenerate JSON Schema for OAS3
tfesenko 687efbe
Merge branch 'master' into task/227
tfesenko 3575040
Merge branch 'master' into task/227
tfesenko 6ca2f96
#227 - fix tests for code-assist for media types - they don't need a …
tfesenko f2251a4
Merge branch 'master' into task/227
tfesenko 3a4675d
#227 - test that an anonymous schema in media types does not have a '…
tfesenko 9f2cd7d
#227 - fix a potential NPE
tfesenko 0baa0ab
[#227] Better code completion proposal for name/key of additional pro…
ghillairet 476b653
Merge branch 'master' into task/227
tfesenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
21 changes: 21 additions & 0 deletions
21
...ezen.swagedit.core/src/com/reprezen/swagedit/core/preferences/KaiZenPreferencesUtils.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,21 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 ModelSolv, Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* ModelSolv, Inc. - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package com.reprezen.swagedit.core.preferences; | ||
|
||
import org.dadacoalition.yedit.preferences.PreferenceConstants; | ||
import org.eclipse.jface.preference.IPreferenceStore; | ||
|
||
public class KaiZenPreferencesUtils { | ||
public static int getTabWidth() { | ||
IPreferenceStore prefs = org.dadacoalition.yedit.Activator.getDefault().getPreferenceStore(); | ||
return prefs.getInt(PreferenceConstants.SPACES_PER_TAB); | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/schema/JsonSchemaUtils.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,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2017 ModelSolv, Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* ModelSolv, Inc. - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package com.reprezen.swagedit.core.schema; | ||
|
||
import static com.google.common.collect.Iterators.transform; | ||
|
||
import java.util.Iterator; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ArrayNode; | ||
import com.google.common.base.Function; | ||
import com.google.common.base.Joiner; | ||
|
||
public class JsonSchemaUtils { | ||
public static String getHumanFriendlyText(JsonNode swaggerSchemaNode, final String defaultValue) { | ||
String schemaTitle = getSchemaTitle(swaggerSchemaNode); | ||
if (schemaTitle != null) { | ||
return schemaTitle; | ||
} | ||
// nested array | ||
if (swaggerSchemaNode.get("items") != null) { | ||
return getHumanFriendlyText(swaggerSchemaNode.get("items"), defaultValue); | ||
} | ||
// "$ref":"#/definitions/headerParameterSubSchema" | ||
JsonNode ref = swaggerSchemaNode.get("$ref"); | ||
if (ref != null) { | ||
return getLabelForRef(ref.asText()); | ||
} | ||
// Auxiliary oneOf in "oneOf": [ { "$ref": "#/definitions/securityRequirement" }] | ||
JsonNode oneOf = swaggerSchemaNode.get("oneOf"); | ||
if (oneOf != null) { | ||
if (oneOf instanceof ArrayNode) { | ||
ArrayNode arrayNode = (ArrayNode) oneOf; | ||
if (arrayNode.size() > 0) { | ||
Iterator<String> labels = transform(arrayNode.elements(), new Function<JsonNode, String>() { | ||
|
||
@Override | ||
public String apply(JsonNode el) { | ||
return getHumanFriendlyText(el, defaultValue); | ||
} | ||
}); | ||
return "[" + Joiner.on(", ").join(labels) + "]"; | ||
} | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
|
||
public static String getSchemaTitle(JsonNode swaggerSchemaNode) { | ||
JsonNode title = swaggerSchemaNode.get("title"); | ||
if (title != null) { | ||
return title.asText(); | ||
} | ||
return null; | ||
} | ||
|
||
public static String getLabelForRef(String refValue) { | ||
return refValue.substring(refValue.lastIndexOf("/") + 1); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
com.reprezen.swagedit.core/src/com/reprezen/swagedit/core/templates/ElementNameResolver.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,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2016 ModelSolv, Inc. and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* ModelSolv, Inc. - initial API and implementation and/or initial documentation | ||
*******************************************************************************/ | ||
package com.reprezen.swagedit.core.templates; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.jface.text.templates.TemplateContext; | ||
import org.eclipse.jface.text.templates.TemplateVariable; | ||
import org.eclipse.jface.text.templates.TemplateVariableResolver; | ||
|
||
/** | ||
* Standard code template variables can only define values that are valid variables, e.g. no space allowed. </br> | ||
* This template variable resolver provides a way to create and select names with special characters (whitespaces, '(', ')') in code templates. For | ||
* example, `${element_name:element_name('(schema name)')}` creates `(schema name)` and selects it for editing. | ||
* | ||
*/ | ||
public class ElementNameResolver extends TemplateVariableResolver { | ||
public ElementNameResolver() { | ||
super("element_name", "Provides human-friendly element name and selects it"); | ||
} | ||
|
||
@Override | ||
public void resolve(TemplateVariable variable, TemplateContext context) { | ||
List params = variable.getVariableType().getParams(); | ||
String[] bindings = new String[params.size()]; | ||
for (int i = 0; i < params.size(); i++) { | ||
bindings[i] = params.get(i).toString(); | ||
} | ||
if (bindings.length != 0) | ||
variable.setValues(bindings); | ||
variable.setResolved(true); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will get a NPE if complexTypes is null here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Addressed in 9f2cd7d