Skip to content
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

Spectral-cli seems to use yaml parser for json files #2720

Open
rudfoss-rr opened this issue Nov 6, 2024 · 1 comment
Open

Spectral-cli seems to use yaml parser for json files #2720

rudfoss-rr opened this issue Nov 6, 2024 · 1 comment

Comments

@rudfoss-rr
Copy link

rudfoss-rr commented Nov 6, 2024

Describe the bug
Simply running the spectral-cli on a json file outputs warning parser Using tabs can lead to unpredictable results for every line with indentation even though the JSON Standard indicates \t is valid whitespace.

To Reproduce

  1. Linting this spec (note \t indentation):
{
	"openapi": "3.0.1",
	"info": {
		"title": "API",
		"version": "v1"
	},
	"paths": {
		"/ping": {
			"get": {
				"tags": ["Ping"],
				"summary": "Simple ping endpoint that returns the server time and a short response.",
				"responses": {
					"200": {
						"description": "Response from a ping request",
						"content": {
							"text/plain": {
								"schema": {
									"$ref": "#/components/schemas/PingDto"
								}
							},
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/PingDto"
								}
							},
							"text/json": {
								"schema": {
									"$ref": "#/components/schemas/PingDto"
								}
							}
						}
					},
					"401": {
						"description": "Unauthorized, a valid JWT-token is required to use this endpoint.",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/DataplatformProblemDetails"
								}
							}
						}
					},
					"403": {
						"description": "Forbidden, user is not allowed to perform this action.",
						"content": {
							"application/json": {
								"schema": {
									"$ref": "#/components/schemas/DataplatformProblemDetails"
								}
							}
						}
					}
				},
				"security": [
					{
						"Bearer": []
					}
				]
			}
		}
	},
	"components": {
		"schemas": {
			"DataplatformProblemDetails": {
				"type": "object",
				"properties": {
					"title": {
						"type": "string",
						"nullable": true
					},
					"status": {
						"type": "integer",
						"format": "int32",
						"nullable": true
					},
					"detail": {
						"type": "string",
						"nullable": true
					},
					"instance": {
						"type": "string",
						"nullable": true
					},
					"type": {
						"type": "string",
						"description": "The type is dynamically constructed from the base URI/DomainName/ProblemType",
						"nullable": true,
						"readOnly": true
					}
				},
				"additionalProperties": {},
				"description": "A domain specific version of the ProblemDetails class. All controllers that return non-successful (4xx, 5xx) responses should return an instance or subclass of this class."
			},
			"PingDto": {
				"required": ["message", "timestamp"],
				"type": "object",
				"properties": {
					"timestamp": {
						"type": "string",
						"format": "date-time"
					},
					"message": {
						"maxLength": 256,
						"minLength": 1,
						"type": "string"
					}
				},
				"additionalProperties": false,
				"description": "Represents a Ping response."
			}
		},
		"securitySchemes": {
			"Bearer": {
				"type": "http",
				"description": "Use a JWT issued by the environments Identity Provider",
				"scheme": "Bearer",
				"bearerFormat": "JWT"
			}
		}
	}
}
  1. Run this CLI command npx spectral lint ./test.json using this .spectral.yaml config produces the unexpected output.
extends: ["spectral:oas", "spectral:asyncapi", "spectral:arazzo"]

Expected behavior
The linter (or parser) should not warn on tab-indentation since it is perfectly valid JSON.

Environment (remove any that are not applicable):

  • Library version: 6.13.1
  • OS: Ubuntu 24/WSL (Windows 11)
  • Browser: N/A

Additional context
According to this issue it can be solved by changing the internal parser, but there does not seem to be an option for that either in .spectral.yaml or as a command-line argument. The CLI should imho also default to the correct parser for the appropriate file format depending on extension or at least some parameter.

@rudfoss-rr
Copy link
Author

I've attempted to address the issue in a PR: #2721

Hope that is OK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant