Commit 153f64a
Add Yaml bean support (#2436)
* "Add support for excluding elements from JSON schema generation"
* Extend Bean class with attributes and properties, remove unnecessary ID exclusion in JSON schema generation
* Validate setId methods and add missing top-level id property
When generating JSON schema for top-level @mcelement classes, enforce that any setId method is exactly setId(String), that at most one exists, and that it is annotated with @MCAttribute using the name "id" (or default). Throw ProcessingException on violations. If no @MCAttribute("id") is present, add an implicit optional "id" string property to the top-level schema.
* Enforce void return type for setId(String) methods and improve error messages
* Include child elements excludedFromJsonSchema when generating JSON Schema; extract bean id from YAML and fix bean index increment
- Comment out early return for cei.excludedFromJsonSchema() so child elements are still added to schema (avoids validation failures)
- Add extractIdOrDefault to GenericYamlParser to use an explicit "id" from the bean node when present
- Use kind variable and correct idx++ placement when creating BeanDefinition entries
* Introduce rootDef to MCElement and add root components support
Add a boolean rootDef() to MCElement (with javadoc) to mark elements allowed at the config root. Mark APIProxy as a root-def element. Add new com.predic8.membrane.core.kubernetes.Components class annotated as a root-def element to represent top-level components with a child elements list and getter/setter.
* Support flow parser types and root defs in JSON schema generation; remove legacy bean; mark Components noEnvelope; relax noEnvelope/topLevel check
- Rename shouldGenerateParserType to shouldGenerateFlowParserType and update all call sites in JsonSchemaGenerator
- Filter root definitions using rootDef() when generating JSON schema top-level defs
- Adjust parser creation logic for flow parser refs
- Remove legacy kubernetes bean field and its getter/setter from Bean.java
- Mark Components as noEnvelope = true on MCElement
- Comment out strict check in SpringConfigurationXSDGeneratingAnnotationProcessor for noEnvelope/topLevel and add TODO notes
* Rename addTopLevelProperties to addRootLevelProperties, update method functionality and comments for clarity.
* Add support for `allOf` in SchemaObject and adjust MCElement annotations in Components
- Introduce `allOf` field and related functionality in SchemaObject for JSON schema generation.
- Update Components class to adjust MCElement annotations by commenting out `noEnvelope` attribute.
* Mark Components as noEnvelope and temporarily disable envelope handling for list items in K8sJsonSchemaGenerator
* rename topLevel to component
* rename topLevel to component
* rename topLevel to component
* rename rootDef to topLevel
* rename rootDef to topLevel
* Generate component-only JSON Schema defs and reference them in components lists
Add createComponentParser and call ensureValidIdSetter for component-only elements.
Make components without a real id gain an optional "id" property; alias schemas
for no-envelope or elements with a real id. Update addChildsAsProperties to use
component-specific $defs names when in a components list context. Add helpers:
isComponentsList, componentDefName, hasRealIdAttribute.
* revert GenericYamlParser changes
* Add first version of using refs to reference component:
current use:
components:
- basicAuthentication:
id: asd
---
api:
port: 2000
flow:
- basicAuthentication:
$ref: asd
------------------------------------------------------
Generate component-or-ref schema definitions and use them for components
- Add createComponentOrRefParser(Model, ElementInfo) to produce a oneOf schema that accepts either the inline component object or a {$ref: string}; handle noEnvelope case by returning a simple ref for now.
- Add componentOrRefDefName helper to name "OrRef" defs.
- Register component-or-ref parser for each element definition.
- Update component name resolution: when an element is a component, use componentDefName in components context, otherwise use componentOrRefDefName so references point to the new oneOf definition.
- Adjust list child processing to reference the OrRef definition for component children.
* Allow list items to be direct $ref component references
Add support for referencing a component instance directly at the list-item
level (allow "- $ref: ...") when the list can contain component types.
Make component schemas simpler: only the components list gets the id-augmented
schema name, remove the separate createComponentOrRefParser and related
helpers, and simplify createComponentParser behavior. Update addChildsAsProperties
signature and adjust schema property requirements accordingly.
* Generate patternProperties for components map and handle otherAttributes value types
- Change Components to store components as Map<String,Object> and use @MCOtherAttributes setter.
- Extend OtherAttributesInfo to detect Map value type (String or Object) and expose ValueType enum.
- In JsonSchemaGenerator, treat @MCOtherAttributes with non-string values as an object map and create a special components parser that uses patternProperties with anyOf variants referencing $defs for component types. Only allow additionalProperties when otherAttributes map values are String.
- Add SchemaObject.patternProperties support and include it in generated JSON output.
* Allow object-level $ref for components in JSON schema
When a type has a child element whose setter expects a component, add an optional
"$ref" string property to the generated object schema so the object can reference
a component via JSON Pointer. Avoid adding the property if a "$ref" already
exists on the parser.
Add hasComponentChild(ElementInfo, MainInfo) to detect component children and
SchemaObject.hasProperty(String) helper to check existing properties.
* Remove unnecessary TODO comments and restore validation logic for @mcelement annotations
- Eliminated outdated and unused TODO comments.
- Reintroduced validation for `noEnvelope=true` with conflicting attributes (e.g., `component=true` or `mixed=true`).
* fixed YAMLParsingTests
* generate the Components class automatically
* Refactor `parseXML` and `parseYAML` logic to share context class loader utility
- Introduced `withContextClassLoader` utility to streamline setting and restoring class loaders.
- Replaced duplicated XML parsing logic with `parseXML` method utilizing `withContextClassLoader`.
- Simplified class loader creation with `xmlClassLoader` for XML parsing.
- Updated tests to use `parseXML` method for Spring XML configurations.
* Enable `errorInListItemUniqueness` test and fix assertion message for schema violations
* Add YAMLComponentsParsingTest, improve test utilities, and fix components setter NPE
- Add YAMLComponentsParsingTest covering component refs and parsing scenarios.
- Add assertStructure(List, Asserter...) helper to StructureAssertionUtil.
- Refactor imports and static imports in CompilerHelper for clarity.
- Initialize this.components and guard null input in generated ComponentClassGenerator#setComponents to avoid NPE when merging maps.
* Support YAML "components" and allow unordered bean assertions
- Parse top-level "components" mapping into BeanDefinition entries (name '#/components/<id>')
- Exclude component beans from activation and from getBeans() listing
- Add GenericYamlParser.extractComponentBeanDefinitions and wrap component nodes
- Make StructureAssertionUtil.assertStructure match expected asserters in any order (backtracking matcher) and improve error reporting
- Remove test that assumed a specific components/api ordering
- Add small BeanDefinition javadoc for constructed bean field
* Validate collection element types and strengthen $ref handling with clearer errors
- Validate element types for Collection setters and throw ParsingException on mismatch.
- Add getCollectionElementType helper and McYamlIntrospector.getElementName().
- Apply object-level $ref earlier; forbid mixing $ref with inline child and enforce allowed component types via grammar checks.
- Improve error messages for component reference and inline+$ref conflicts and update tests accordingly.
* Refactor MethodSetter to improve collection handling and remove unused $ref logic
- Simplify collection parsing by cleaning imports and updating parseListIncludingStartEvent usage.
- Extend getCollectionElementType to handle WildcardType upper bounds.
- Remove obsolete $ref handler in GenericYamlParser.
* Remove unused `lazyInit` property and related methods in `Bean` class
- Clean up code by eliminating unused property `lazyInit` and associated getter, setter, and comment.
* Add test for component referencing another component in YAML parsing
- Introduce `componentRefersToAnotherComponent` test in `YAMLComponentsParsingTest`.
- Verify nested component references and parsing correctness with assertions for structure.
* Prevent top-level elements from being used as nested children in JSON schema
- Update `JsonSchemaGenerator` to filter out top-level elements when adding nested properties.
- Add tests in `YAMLComponentsParsingTest` to verify restrictions and allow correct placement of top-level elements.
* Remove component-only JSON Schema parsers and id setter validation, tidy imports, and use method reference in McYamlIntrospector
* Refactor `JsonSchemaGenerator` to use constants for "components" and ID pattern, remove unused `excludedFromJsonSchema` method
- Replaced repeated string literals with `COMPONENTS` and `COMPONENT_ID_PATTERN` constants.
- Cleaned up related `isComponentsMap` and `isComponentsList` logic to use constants.
- Removed unused `excludedFromJsonSchema` method from `ChildElementInfo` to simplify codebase.
* Add excludeFromFlow to @mcelement, mark interceptors excluded from flow, and simplify JsonSchemaGenerator
* Refactor `$ref` handling in `GenericYamlParser` for improved error clarity and inline conflict prevention
* Remove unused `excludeFromFlow` set and `componentDefName` method in `JsonSchemaGenerator`
- Simplify `JsonSchemaGenerator` by cleaning up redundant code.
- Remove unused `excludeFromFlow` set and `componentDefName` helper function for better maintainability.
* Add documentation and implement missing attributes in `Bean`, `ConstructorArg`, and `Property` classes
- Provide YAML configuration example for `Bean`.
- Remove unused `id` property from `Bean`.
- Add getters and setters for `value` and `ref` in `ConstructorArg` and `Property`.
* Add BeanClassGenerator to produce Bean at compile time, invoke it from the annotation processor, and remove the old core Bean implementation
* fix BeanClassGenerator
* Add `BeanFactory` for dynamic bean instantiation and integrate prototype handling in `BeanRegistryImplementation`
- Introduced `BeanFactory` to create Java objects from YAML "bean" nodes with support for constructor arguments and properties.
- Enhanced `BeanRegistryImplementation` to distinguish and handle singleton vs. prototype beans.
- Added `YAMLBeanParsingTest` for comprehensive validation of bean instantiation and lifecycle management.
* Refactor `BeanRegistryImplementation` to improve error handling and simplify prototype scope checks
- Replaced `IOException` with `RuntimeException` in `define` for better error propagation.
- Simplified prototype scope check using default value in `JsonNode`.
- Removed unused bean scopes in `BeanClassGenerator`.
* Add example for custom interceptor using YAML configuration
- Created `apis.yaml` to demonstrate defining and using a custom interceptor in the flow.
- Updated `README.md` to reflect the new YAML-based example, replacing the previous XML format.
* Refactor `BeanFactory` to improve class loading and enhance error assertions in `YAMLBeanParsingTest`
- Added `loadBeanClass` method in `BeanFactory` to streamline and prioritize class loading from multiple class loaders.
- Updated error assertions in `YAMLBeanParsingTest` for better coverage and clearer schema error validation.
* Update license header in `YAMLBeanParsingTest` for compliance with Apache License 2.0.
* coderabbit fixes
* Refactor `ComponentClassGenerator` and `BeanClassGenerator` to extend abstract `ClassGenerator`
- Introduced `ClassGenerator` as an abstract base class to encapsulate shared functionality.
- Simplified `ComponentClassGenerator` and `BeanClassGenerator` by moving common logic to `ClassGenerator`.
* minor
* Update license headers for compliance and enhance bean reference support in YAML parsing
- Added Apache License 2.0 headers to multiple files for compliance.
- Improved YAML parsing in `MethodSetter` to support bean reference resolution with type checks.
* fix Parsing
* refactor: simplify `BeanFactory` code and streamline property parsing
- Renamed `createFromNode()` to `create()` for clarity.
- Introduced `Property` class for improved property handling.
- Refactored redundant code for better readability and maintained behavior consistency.
- Enhanced formatting of exception messages for uniformity.
* Refactor `BeanFactory` to simplify constructor argument parsing with streamlined logic and improved readability.
* coderabbit suggestions
* refactor: improve code readability and modularity across `annot` package
- Simplified key matching logic in `McYamlIntrospector` and introduced helper methods.
- Extracted repetitive logic into reusable methods, e.g., `getReferenced` and `guardHasMCAttributeSetters`.
- Introduced additional validation and utility methods in `BeanDefinition` and `BeanRegistryImplementation`.
- Streamlined schema generation logic in `JsonSchemaGenerator`, reducing redundancy in object creation and property handling.
- Enhanced `Grammar`'s source file creation and assembly logic for clearer responsibility separation.
* refactor: remove unused methods and make lists immutable in `annot` package
- Removed redundant getters and setters in `Grammar` and `ElementInfo`.
- Marked `ais` and `ceis` lists in `ElementInfo` as `final` to ensure immutability.
- Cleaned up unused return documentation in `McYamlIntrospector`.
* refactor: streamline code and improve readability in `annot` package
- Simplified property-checking logic using streams in `SchemaObject`.
- Corrected method name typo from `stripFistLine` to `stripFirstLine` in `CompilerHelper`.
- Replaced inner `Pair` class with `record` for better conciseness.
- Improved formatting and consistency in generated content for `Grammar`.
* feat: add ReflectionUtil with type conversion and primitive-wrapper utility methods
- Introduced `ReflectionUtil` for converting string values to specified Java types.
- Added `isWrapperOfPrimitive` method for validating primitive-wrapper type relationships.
- Included comprehensive JUnit tests for all utility methods.
* refactor: streamline `CompilerHelper` code and enhance modularity
- Consolidated repetitive class loader overlay logic into a reusable `overlayClassLoader` method.
- Simplified `withContextClassLoader` error handling for better clarity.
- Resolved minor issues in object creation with `APPLICATION_CONTEXT_CLASSNAME` instance lifecycle management.
- Improved imports organization and reduced redundancy in both structure and functionality.
* Refactor `YAMLBeanParsingTest` to split tests by scope, update scope annotation in `BeanDefinition`, and clarify `BeanFactory` class loading logic
* Add `Scope` enum, update exception type in `OtherAttributesInfo`, and import `Scope` in `BeanClassGenerator`.
- Introduced `Scope` enum with `SINGLETON` and `PROTOTYPE` values.
- Replaced `IllegalArgumentException` with `ProcessingException` for better exception handling in `OtherAttributesInfo`.
- Added `Scope` import to `BeanClassGenerator`.
* refactor: avoid NPE
---------
Co-authored-by: Tobias Polley <mail@tobias-polley.de>
Co-authored-by: Thomas Bayer <bayer@predic8.de>1 parent 414b1ca commit 153f64a
121 files changed
Lines changed: 2624 additions & 681 deletions
File tree
- annot/src
- main/java/com/predic8/membrane/annot
- bean
- generator
- kubernetes
- model
- model
- util
- yaml
- test/java/com/predic8/membrane/annot
- util
- core/src/main/java/com/predic8/membrane/core
- azure
- config
- security/acme
- xml
- interceptor
- adminapi
- apikey
- extractors
- stores/inConfig
- authentication
- session
- xen
- balancer
- flow
- choice
- formvalidation
- grease/strategies
- groovy
- jwt
- kubernetes
- log
- ntlm
- oauth2client
- oauth2server
- oauth2
- authorizationservice
- tokengenerators
- opentelemetry
- exporter
- registration
- rest
- rewrite
- schemavalidation/json
- session
- tunnel
- ws_addressing
- kubernetes
- openapi/serviceproxy
- proxies
- sslinterceptor
- transport/http/client
- util
- distribution
- examples/extending-membrane/custom-interceptor
- src/test/java/com/predic8/membrane/examples/withoutinternet
- docs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
34 | 36 | | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
33 | | - | |
| 38 | + | |
34 | 39 | | |
35 | 40 | | |
36 | 41 | | |
| |||
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
57 | 67 | | |
Lines changed: 13 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
219 | | - | |
| 218 | + | |
| 219 | + | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
223 | | - | |
224 | 222 | | |
225 | 223 | | |
226 | 224 | | |
| |||
254 | 252 | | |
255 | 253 | | |
256 | 254 | | |
257 | | - | |
258 | | - | |
| 255 | + | |
| 256 | + | |
259 | 257 | | |
260 | 258 | | |
261 | 259 | | |
| |||
272 | 270 | | |
273 | 271 | | |
274 | 272 | | |
275 | | - | |
276 | | - | |
277 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
278 | 276 | | |
279 | 277 | | |
280 | 278 | | |
| |||
299 | 297 | | |
300 | 298 | | |
301 | 299 | | |
302 | | - | |
| 300 | + | |
303 | 301 | | |
304 | | - | |
| 302 | + | |
305 | 303 | | |
306 | 304 | | |
307 | 305 | | |
| |||
512 | 510 | | |
513 | 511 | | |
514 | 512 | | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
| |||
Lines changed: 252 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
0 commit comments