class Detector::Specification::Oas3

Defined in:

detector/detectors/specification/oas3.cr

Constant Summary

OPENAPI3_JSON_MARKER = /"openapi"[ \t]*:[ \t]*"3\./

JSON gets no such structural guarantee — "openapi": "3.0.0" can sit nested inside a wrapper document — so the JSON branch keeps parsing and checking the root key, and the regex only serves as a cheap pre-gate.

OPENAPI3_YAML_MARKER = /^["']?openapi["']?[ \t]*:[ \t]*["']?3\./m

Every .json/.yaml/.yml in the tree reaches this gate. A bare /openapi/ matched any document that merely mentions OpenAPI — an x-origin: {url: .../openapi.yaml} block, a description, a swagger document that links to its own OAS3 conversion — and each of those paid for a full YAML/JSON parse before being rejected.

In YAML a key at column 0 is a root key: a block scalar's content must be indented past the key that introduces it, so an openapi: 3.x line starting at column 0 cannot be anything but the document's version field. That makes the anchored match as strong as the parse it replaces, so the YAML branch registers on the regex alone and lets the analyzer — which parses the document anyway — be the one that reads it. Previously every OpenAPI document in the tree was parsed twice: once to decide, once to analyze, with the first parse thrown away.

Class Method Summary

Instance Method Summary

Instance methods inherited from class Detector

applicable?(filename : String) : Bool applicable?, base_relative_path(filename : String) : String base_relative_path, content_matches?(file_contents : String, markers : Regex) : Bool content_matches?, detect(filename : String, file_contents : String) : Bool detect, gemfile_dependency?(file_contents : String, gem_name : String) : Bool gemfile_dependency?, gemspec_dependency?(file_contents : String, gem_name : String) : Bool gemspec_dependency?, idempotent? : Bool idempotent?, logger : NoirLogger logger, name : String name, path_sensitive? : Bool path_sensitive?

Constructor methods inherited from class Detector

new(options : Hash(String, YAML::Any)) new

Macros inherited from class Detector

detector_for(tech, extensions = nil, basenames = nil, path_segments = nil, idempotent = nil) detector_for

Class Method Detail

def self.tech_name : String #

The tech name without needing an instance, so the registry can be read off the classes themselves rather than from a parallel list.


[View source]

Instance Method Detail

def applicable?(filename : String) : Bool #

Registers every OAS3 spec path in CodeLocator for the analyzer pass. Must keep running after first match.


[View source]
def detect(filename : String, file_contents : String) : Bool #

[View source]
def idempotent? : Bool #

Registers every OAS3 spec path in CodeLocator for the analyzer pass. Must keep running after first match.


[View source]
def set_name #

Registers every OAS3 spec path in CodeLocator for the analyzer pass. Must keep running after first match.


[View source]