async def test_generate_openapi_definition(server: Server, feature_manager: FeatureManager, patch_openapi_spec_validator: None): global_url_map = server._transport.get_global_url_map(server.get_slices().values()) openapi = OpenApiConverter(global_url_map, feature_manager) openapi_json = openapi.generate_openapi_json() assert openapi_json openapi_parsed = json.loads(openapi_json) openapi_v3_spec_validator.validate(openapi_parsed)
def test_get_swagger_json_is_not_valid_openapi_v3(): """Verify that /api/swagger.json file does NOT comply with OpenAPI v3.""" response = _get_request(ROOT_URL + SWAGGER_JSON_PATH) spec_dict = loads(response.text) with pytest.raises(OpenAPIValidationError): openapi_v3_spec_validator.validate(spec_dict) assert response.status_code == HTTPStatus.OK
def create(self, spec_dict, spec_url=''): if self.config.get('validate_spec', True): openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url) spec_dict_deref = self.dereferencer.dereference(spec_dict) info_spec = spec_dict_deref.get('info', {}) servers_spec = spec_dict_deref.get('servers', []) paths = spec_dict_deref.get('paths', {}) components_spec = spec_dict_deref.get('components', {}) if not servers_spec: servers_spec = [ { 'url': '/' }, ] info = self.info_factory.create(info_spec) servers = self.servers_generator.generate(servers_spec) paths = self.paths_generator.generate(paths) components = self.components_factory.create(components_spec) spec = Spec( info, list(paths), servers=list(servers), components=components, _resolver=self.spec_resolver, ) return spec
def create_spec( spec_dict, spec_url='', handlers=default_handlers, validate_spec=True, ): if validate_spec: openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url) spec_resolver = RefResolver( spec_url, spec_dict, handlers=handlers) spec_factory = SpecFactory(spec_resolver) return spec_factory.create(spec_dict, spec_url=spec_url)
def create_spec( spec_dict, spec_url="", handlers=default_handlers, validate_spec=True, ): if validate_spec: openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url) spec_resolver = RefResolver(spec_url, spec_dict, handlers=handlers) dereferencer = Dereferencer(spec_resolver) return SpecPath.from_spec(spec_dict, dereferencer)
async def test_openapi_endpoint(client, patch_openapi_spec_validator: None): result = await client.get_api_docs("openapi") assert result.code == 200 openapi_spec = result.result["data"] openapi_v3_spec_validator.validate(openapi_spec)