-
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
Conversation
…omizations for the 'property'
…y the 'additionalProperties'
…so has a 'title'
…tes) caused by invalid tab width pref
… format '(schema name)' and select it for editing
…the _end_ of the inserted proposal
Generated using commit 83638080c70784ca84fcfbf86af948c6e98bcbba on https://github.com/RepreZen/gnostic/tree/task/KZOE-227
@ghillairet , @tedepstein , this PR is ready for review. |
Looks good, Tanya! I will plan to test it after it has passed code review and been merged. |
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.
|
||
@Override | ||
public String getLabel() { | ||
return Iterables.getFirst(complexTypes, null).getLabel(); |
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
…_key_' proposal in code assist
@ghillairet , thanks for reporting a case with a |
…perties Add test to show that _key_ is still present in content assist for response content schema.
@tfesenko See my commit that adds a test to show that key is still present for response content schema. |
@ghillairet , I extracted #411 " |
This PR provides better completion proposals and code templates for properties described as additionalProperties in OAS3 and Swagger v3
OAS3
Code assist
(<element> name)
is proposed for elements described withadditionalProperties
in JSON Schema. When chosen, the new name is selected for editing.In this screencast, code assist suggests
(schema name)
for a schema and then(property name)
for a schema describing a property:Similar approach applies to other components (
callbacks
,links
,examples
, etc) and otheradditionalProperties
:I am not attaching screenshots for all supported cases as I have provided tests for them.
Tests
OpenApi3ContentAssistProcessorTest
provides tests for all major cases:Note that some elements still have strange names:
_type_
_type_
(any name)
Current status is covered by tests.
Implementation
JsonProposalProvider
creates proposal for theadditionalProperties
elements. The label is described by a newTypeDefinition#getLabel()
which tried to get needed information from JSON Schema. For the schema property, we can't infer the needed name -property
- from the schema, so I added atitle
property to JSON Schema.JSON Schema
I had to add one line to the JSON Schema to provide a correct
(property name)
instead of(schema name)
To do it, I updated our JSON Schema generator. It's generated using commit 83638080c70784ca84fcfbf86af948c6e98bcbba on
https://github.com/RepreZen/gnostic/tree/task/KZOE-227
Code templates
Named schemas and properties now have code templates for major cases. These code templates are generated by
Activator.addNamedSchemaTemplatesInSchemas()
andaddNamedSchemaTemplatesInSchemaProperties()
using already existing code templates defined for inline schemas intemplates.xml
.I also added code template for a schema ref for schema properties.
Tests
SchemaObject.yaml
. It means that our JUnit tests verify that:Known issues
Restore Defaults on KaiZen>OpenAPI v3/Templates preferences page erases synthetic code templates generated for named schema and named property.
Implementation
Activator.addNamedSchemaTemplatesInSchemas()
andaddNamedSchemaTemplatesInSchemaProperties()
build code templates dynamically(schema name)
. So I addedElementNameResolver
to handle it.Swagger v2
Code assist
Similar code assist experience was implemented for Swagger v2:
I provided several tests for
(schema name)
and(property name)
inSwaggerProposalProviderTest
, but I did not test it as thorough as foer OAS 3.Code templates
I did NOT provide synthetic code templates for named schemas in Swagger v2. Anyway, only one code template is available for a named schema,
JSON Schema
Again, JSON Schema was modified to provide a correct value for
(property name)
, but as JSON Schema for Swagger v2 is not generated, there is no need to update the schema generator.