private void generatePerGroup()

in src/main/java/aws/cfn/codegen/json/Codegen.java [119:188]


    private void generatePerGroup(List<String> definitionNames,
                                  Map<String, File> groupSchemas,
                                  Map<String, ObjectNode> groupSpecDefinitions,
                                  CfnSpecification specification) {

        final Boolean includeIntrinsics = this.config.getSettings().getIncludeIntrinsics();
        final String intrinsics = includeIntrinsics != null && includeIntrinsics ?
            intrinsics() : "";

        groupSpecDefinitions.entrySet().stream()
            // Add resources block to each
            .map(e -> {
                ObjectNode definitions = e.getValue();

                // Add alternative custom resources
                ObjectNode customResource = definitions.putObject("altCustomResource");
                customResource.put("type", "object");
                ObjectNode custProperties = customResource.putObject("properties");
                ObjectNode custType = custProperties.putObject("Type");
                custType.put("type", "string");
                custType.put("pattern", "Custom::[A-Za-z0-9]+");
                custType.put("maxLength", 60);
                ObjectNode custProp = custProperties.putObject("Properties");
                custProp.put("type", "object");
                ArrayNode required = customResource.putArray("required");
                required.add("Type");
                required.add("Properties");
                customResource.put("additionalProperties", false);
                addDependsOn(custProperties);

                ObjectNode resourcesDefnSide = definitions.putObject("resources");
                resourcesDefnSide.put("type", "object");
                resourcesDefnSide.put("additionalProperties", false);
                resourcesDefnSide.put("minProperties", 1);
                ObjectNode patternProps = resourcesDefnSide.putObject("patternProperties");
                ObjectNode resourceProps = patternProps.putObject("^[a-zA-Z0-9]{1,255}$");
                ArrayNode anyOf = resourceProps.putArray("oneOf");
                ObjectNode ref = anyOf.addObject();
                ref.put("$ref", "#/definitions/altCustomResource");
                for (String eachDefn: definitionNames) {
                    if (definitions.has(eachDefn)) {
                        ref = anyOf.addObject();
                        ref.put("$ref", "#/definitions/" + eachDefn);
                    }
                }
                return e;
            })
            // Write each output file
            .forEach(e -> {
                try {
                    Map<String, Object> variables = new HashMap<>(5);
                    variables.put("draft", draft());
                    String res =
                        mapper.writerWithDefaultPrettyPrinter().writeValueAsString(e.getValue());
                    variables.put("intrinsics", intrinsics);
                    variables.put("resources", res.substring(1, res.length() - 1));
                    String description = "CFN JSON specification generated from version " +
                        specification.getResourceSpecificationVersion();
                    variables.put("description", description);
                    Mustache cfnSchema = new DefaultMustacheFactory().compile("Schema.template");
                    cfnSchema.execute(new OutputStreamWriter(
                        new FileOutputStream(groupSchemas.get(e.getKey())),
                        StandardCharsets.UTF_8
                    ), variables).flush();
                }
                catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            });
    }