swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.95k stars 2.26k forks source link

SwaggerEditor@next: syntax highlight for $ref key not working #3624

Open tim-lai opened 2 years ago

tim-lai commented 2 years ago

Q&A (please complete the following information)

Content & configuration

use fixtures on editor-next.swagger.io. e.g. any of OpenAPI 3.0 Petstore Fixture, AsyncAPI 2.5 Streetlights Fixture, OpenAPI 3.1 Fixture

Describe the bug you're encountering

Display of semantic highlighting for $ref is not working. Applies to various possible Reference Object locations. In the dark theme, $ref currently appears as grey.

To reproduce...

Steps to reproduce the behavior:

  1. Use fixtures on editor-next.swagger.io. e.g. any of OpenAPI 3.0 Petstore Fixture, AsyncAPI 2.5 Streetlights Fixture, OpenAPI 3.1 Fixture
  2. Look for any $ref
  3. See grey color appearance

Expected behavior

The $ref key should be non-grey color. Currently expecting "orange-ish", but could also have fontStyle: "bold" and/or be a different color.

Screenshots

Additional context or thoughts

frantuma commented 2 years ago

@char0n @tim-lai

This is because we don't have metadata for ref key (it's just a string), and mechanism is based on metadata.

we can solve this either :

  1. by adding metadata to $ref keys elements

or

  1. tweaking logic for this specific case, harcoding some name to map these keys with, like reference-value-key or something, this would not work for languages/format where such keys are named differently than $ref; this is not something we have at the moment though.

In terms of "right way" I'd say Option 1 maybe better (you'd probably be quicker to add these changes to reference elements in namespaes), but no strong objection at this stage to go for the non-metadata Option 2

Please let me know what you think

char0n commented 2 years ago

@frantuma, right 1.) is systematic solution so let's go for it.

Here is how the metadata will look like after this issue is processed:

Symbolic Expression representation:

ReferenceElement // classes: [reference-element]
  MemberElement
    key=$ref // classes: [reference-key]
    value=<abtirary> // classes: [reference-value]

Classes reference-element and reference-value are already present. The scope of this issue is to add the reference-key class metadata.

frantuma commented 2 years ago

@char0n excellent, just a note: the reference-key added to classes should be added to tokens