oas_rails 0.3.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/app/controllers/oas_rails/oas_rails_controller.rb +1 -1
- data/app/views/oas_rails/oas_rails/index.html.erb +1 -1
- data/lib/generators/oas_rails/config/templates/oas_rails_initializer.rb +11 -0
- data/lib/oas_rails/builders/content_builder.rb +55 -0
- data/lib/oas_rails/builders/operation_builder.rb +32 -0
- data/lib/oas_rails/builders/parameter_builder.rb +28 -0
- data/lib/oas_rails/builders/parameters_builder.rb +39 -0
- data/lib/oas_rails/builders/path_item_builder.rb +22 -0
- data/lib/oas_rails/builders/request_body_builder.rb +61 -0
- data/lib/oas_rails/builders/response_builder.rb +40 -0
- data/lib/oas_rails/builders/responses_builder.rb +58 -0
- data/lib/oas_rails/configuration.rb +17 -5
- data/lib/oas_rails/extractors/oas_route_extractor.rb +66 -0
- data/lib/oas_rails/extractors/render_response_extractor.rb +11 -36
- data/lib/oas_rails/oas_route.rb +0 -5
- data/lib/oas_rails/spec/components.rb +85 -0
- data/lib/oas_rails/spec/contact.rb +18 -0
- data/lib/oas_rails/spec/hashable.rb +39 -0
- data/lib/oas_rails/{info.rb → spec/info.rb} +30 -24
- data/lib/oas_rails/spec/license.rb +18 -0
- data/lib/oas_rails/spec/media_type.rb +84 -0
- data/lib/oas_rails/spec/operation.rb +25 -0
- data/lib/oas_rails/spec/parameter.rb +34 -0
- data/lib/oas_rails/spec/path_item.rb +33 -0
- data/lib/oas_rails/spec/paths.rb +26 -0
- data/lib/oas_rails/spec/reference.rb +16 -0
- data/lib/oas_rails/spec/request_body.rb +21 -0
- data/lib/oas_rails/spec/response.rb +20 -0
- data/lib/oas_rails/spec/responses.rb +25 -0
- data/lib/oas_rails/spec/server.rb +17 -0
- data/lib/oas_rails/spec/specable.rb +51 -0
- data/lib/oas_rails/spec/specification.rb +50 -0
- data/lib/oas_rails/spec/tag.rb +18 -0
- data/lib/oas_rails/utils.rb +59 -0
- data/lib/oas_rails/version.rb +1 -1
- data/lib/oas_rails.rb +41 -16
- metadata +29 -17
- data/lib/oas_rails/contact.rb +0 -12
- data/lib/oas_rails/license.rb +0 -11
- data/lib/oas_rails/media_type.rb +0 -102
- data/lib/oas_rails/oas_base.rb +0 -30
- data/lib/oas_rails/operation.rb +0 -134
- data/lib/oas_rails/parameter.rb +0 -47
- data/lib/oas_rails/path_item.rb +0 -25
- data/lib/oas_rails/paths.rb +0 -19
- data/lib/oas_rails/request_body.rb +0 -29
- data/lib/oas_rails/response.rb +0 -12
- data/lib/oas_rails/responses.rb +0 -20
- data/lib/oas_rails/server.rb +0 -10
- data/lib/oas_rails/specification.rb +0 -72
- data/lib/oas_rails/tag.rb +0 -17
data/lib/oas_rails/server.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module OasRails
|
4
|
-
class Specification
|
5
|
-
# Initializes a new Specification object.
|
6
|
-
# Clears the cache if running in the development environment.
|
7
|
-
def initialize
|
8
|
-
clear_cache unless Rails.env.production?
|
9
|
-
|
10
|
-
@specification = base_spec
|
11
|
-
end
|
12
|
-
|
13
|
-
# Clears the cache for MethodSource and RouteExtractor.
|
14
|
-
#
|
15
|
-
# @return [void]
|
16
|
-
def clear_cache
|
17
|
-
MethodSource.clear_cache
|
18
|
-
Extractors::RouteExtractor.clear_cache
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_json(*_args)
|
22
|
-
@specification.to_json
|
23
|
-
rescue StandardError => e
|
24
|
-
Rails.logger.error("Error Generating OAS: #{e.message}")
|
25
|
-
{}
|
26
|
-
end
|
27
|
-
|
28
|
-
# Create the Base of the OAS hash.
|
29
|
-
# @see https://spec.openapis.org/oas/latest.html#schema
|
30
|
-
def base_spec
|
31
|
-
{
|
32
|
-
openapi: '3.1.0',
|
33
|
-
info: OasRails.config.info.to_spec,
|
34
|
-
servers: OasRails.config.servers.map(&:to_spec),
|
35
|
-
paths:,
|
36
|
-
components:,
|
37
|
-
security:,
|
38
|
-
tags: OasRails.config.tags.map(&:to_spec),
|
39
|
-
externalDocs: {}
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
# Create the Security Requirement Object.
|
44
|
-
# @see https://spec.openapis.org/oas/latest.html#security-requirement-object
|
45
|
-
def security
|
46
|
-
return [] unless OasRails.config.authenticate_all_routes_by_default
|
47
|
-
|
48
|
-
OasRails.config.security_schemas.map { |key, _| { key => [] } }
|
49
|
-
end
|
50
|
-
|
51
|
-
# Create the Paths Object For the Root of the OAS.
|
52
|
-
# @see https://spec.openapis.org/oas/latest.html#paths-object
|
53
|
-
def paths
|
54
|
-
Paths.from_string_paths(string_paths: Extractors::RouteExtractor.host_paths).to_spec
|
55
|
-
end
|
56
|
-
|
57
|
-
# Created the Components Object For the Root of the OAS.
|
58
|
-
# @see https://spec.openapis.org/oas/latest.html#components-object
|
59
|
-
def components
|
60
|
-
{
|
61
|
-
schemas: {}, parameters: {}, securitySchemes: security_schemas, requestBodies: {}, responses: {},
|
62
|
-
headers: {}, examples: {}, links: {}, callbacks: {}
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
# Create the Security Schemas Array inside components field of the OAS.
|
67
|
-
# @see https://spec.openapis.org/oas/latest.html#security-scheme-object
|
68
|
-
def security_schemas
|
69
|
-
OasRails.config.security_schemas
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/lib/oas_rails/tag.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
module OasRails
|
2
|
-
class Tag
|
3
|
-
attr_accessor :name, :description
|
4
|
-
|
5
|
-
def initialize(name:, description:)
|
6
|
-
@name = name.titleize
|
7
|
-
@description = description
|
8
|
-
end
|
9
|
-
|
10
|
-
def to_spec
|
11
|
-
{
|
12
|
-
name: @name,
|
13
|
-
description: @description
|
14
|
-
}
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|