oas_rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -0
  3. data/app/controllers/oas_rails/oas_rails_controller.rb +1 -1
  4. data/lib/generators/oas_rails/config/templates/oas_rails_initializer.rb +11 -0
  5. data/lib/oas_rails/builders/content_builder.rb +55 -0
  6. data/lib/oas_rails/builders/operation_builder.rb +32 -0
  7. data/lib/oas_rails/builders/parameter_builder.rb +28 -0
  8. data/lib/oas_rails/builders/parameters_builder.rb +39 -0
  9. data/lib/oas_rails/builders/path_item_builder.rb +22 -0
  10. data/lib/oas_rails/builders/request_body_builder.rb +60 -0
  11. data/lib/oas_rails/builders/response_builder.rb +40 -0
  12. data/lib/oas_rails/builders/responses_builder.rb +58 -0
  13. data/lib/oas_rails/configuration.rb +17 -5
  14. data/lib/oas_rails/extractors/oas_route_extractor.rb +66 -0
  15. data/lib/oas_rails/extractors/render_response_extractor.rb +11 -36
  16. data/lib/oas_rails/oas_route.rb +0 -5
  17. data/lib/oas_rails/spec/components.rb +85 -0
  18. data/lib/oas_rails/spec/contact.rb +18 -0
  19. data/lib/oas_rails/spec/hashable.rb +39 -0
  20. data/lib/oas_rails/{info.rb → spec/info.rb} +30 -24
  21. data/lib/oas_rails/spec/license.rb +18 -0
  22. data/lib/oas_rails/spec/media_type.rb +84 -0
  23. data/lib/oas_rails/spec/operation.rb +25 -0
  24. data/lib/oas_rails/spec/parameter.rb +34 -0
  25. data/lib/oas_rails/spec/path_item.rb +33 -0
  26. data/lib/oas_rails/spec/paths.rb +26 -0
  27. data/lib/oas_rails/spec/reference.rb +16 -0
  28. data/lib/oas_rails/spec/request_body.rb +21 -0
  29. data/lib/oas_rails/spec/response.rb +20 -0
  30. data/lib/oas_rails/spec/responses.rb +25 -0
  31. data/lib/oas_rails/spec/server.rb +17 -0
  32. data/lib/oas_rails/spec/specable.rb +51 -0
  33. data/lib/oas_rails/spec/specification.rb +50 -0
  34. data/lib/oas_rails/spec/tag.rb +18 -0
  35. data/lib/oas_rails/utils.rb +39 -0
  36. data/lib/oas_rails/version.rb +1 -1
  37. data/lib/oas_rails.rb +41 -16
  38. metadata +29 -17
  39. data/lib/oas_rails/contact.rb +0 -12
  40. data/lib/oas_rails/license.rb +0 -11
  41. data/lib/oas_rails/media_type.rb +0 -102
  42. data/lib/oas_rails/oas_base.rb +0 -30
  43. data/lib/oas_rails/operation.rb +0 -134
  44. data/lib/oas_rails/parameter.rb +0 -47
  45. data/lib/oas_rails/path_item.rb +0 -25
  46. data/lib/oas_rails/paths.rb +0 -19
  47. data/lib/oas_rails/request_body.rb +0 -29
  48. data/lib/oas_rails/response.rb +0 -12
  49. data/lib/oas_rails/responses.rb +0 -20
  50. data/lib/oas_rails/server.rb +0 -10
  51. data/lib/oas_rails/specification.rb +0 -72
  52. data/lib/oas_rails/tag.rb +0 -17
@@ -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