Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.brapi.schematools.core.openapi.generator.OpenAPIWriter;
import org.brapi.schematools.core.openapi.generator.metadata.OpenAPIGeneratorMetadata;
import org.brapi.schematools.core.openapi.generator.options.OpenAPIGeneratorOptions;
import org.brapi.schematools.core.r.generator.RGenerator;
import org.brapi.schematools.core.r.RGenerator;
import org.brapi.schematools.core.r.metadata.RGeneratorMetadata;
import org.brapi.schematools.core.r.options.RGeneratorOptions;
import org.brapi.schematools.core.response.Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.brapi.schematools.core.r.generator;
package org.brapi.schematools.core.r;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -67,6 +67,21 @@ public RGenerator(RGeneratorOptions options, Path outputPath) {
* @param schemaDirectory the path to the complete BrAPI Specification
* @return the paths of the Markdown files generated from the complete BrAPI Specification
*/
public Response<List<Path>> generate(Path schemaDirectory) {
return generate(schemaDirectory, RGeneratorMetadata.load()) ;
}

/**
* Generates SQL files for type and their field descriptions
* from the complete BrAPI Specification in
* a directory contains a subdirectories for each module that contain
* the BrAPI JSON schema and the additional subdirectories called 'Requests'
* that contains the request schemas and BrAPI-Common that contains common schemas
* for use across modules.
* @param schemaDirectory the path to the complete BrAPI Specification
* @param metadata the metadata for the generator
* @return the paths of the Markdown files generated from the complete BrAPI Specification
*/
public Response<List<Path>> generate(Path schemaDirectory, RGeneratorMetadata metadata) {
return schemaReader.readDirectories(schemaDirectory)
.mapResultToResponse(brAPISchemas -> new Generator(brAPISchemas, metadata).generate()) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import lombok.experimental.Accessors;
import org.brapi.schematools.core.brapischema.BrAPISchemaReaderOptions;
import org.brapi.schematools.core.model.BrAPIObjectProperty;
import org.brapi.schematools.core.model.BrAPIObjectType;
import org.brapi.schematools.core.model.BrAPIType;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class RGeneratorOptions extends AbstractGeneratorOptions {
private Map<String, String> pathItemNameFor = new HashMap<>();
@Setter(AccessLevel.PRIVATE)
private Map<String, Map<String, String>> pathItemNameForProperty = new HashMap<>();
@Setter(AccessLevel.PRIVATE)
private BrAPISchemaReaderOptions brAPISchemaReader ;

/**
* Load the default options
Expand All @@ -65,7 +68,17 @@ public class RGeneratorOptions extends AbstractGeneratorOptions {
*/
public static RGeneratorOptions load() {
try {
return ConfigurationUtils.load("r-options.yaml", RGeneratorOptions.class);
RGeneratorOptions options = ConfigurationUtils.load("r-options.yaml", RGeneratorOptions.class);

if (options.getBrAPISchemaReader() == null) {
options.setBrAPISchemaReader(BrAPISchemaReaderOptions.load());
} else {
options.setBrAPISchemaReader(
BrAPISchemaReaderOptions.load().override(options.getBrAPISchemaReader())
) ;
}

return options ;
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -116,7 +129,9 @@ public Validation validate() {
.merge(search)
.merge(properties)
.merge(controlledVocabulary)
.assertNotNull(pathItemNameFor, "'pathItemNameFor' option is null") ;
.assertNotNull(pathItemNameFor, "'pathItemNameFor' option is null")
.assertNotNull(brAPISchemaReader, "'brAPISchemaReader' options on %s is null", this.getClass().getSimpleName())
.merge(brAPISchemaReader);
}

/**
Expand Down Expand Up @@ -186,6 +201,10 @@ public RGeneratorOptions override(RGeneratorOptions overrideOptions) {
controlledVocabulary = overrideOptions.controlledVocabulary ;
}

if (overrideOptions.brAPISchemaReader != null) {
brAPISchemaReader.override(overrideOptions.brAPISchemaReader);
}

return this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.brapi.schematools.core.sql.options;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
import lombok.experimental.Accessors;
import org.brapi.schematools.core.brapischema.BrAPISchemaReaderOptions;
import org.brapi.schematools.core.options.AbstractGeneratorSubOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.brapi.schematools.core.validiation;

import com.networknt.schema.SpecVersion;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import lombok.extern.slf4j.Slf4j;
import org.brapi.schematools.core.graphql.options.*;
import org.brapi.schematools.core.model.BrAPIObjectProperty;
import org.brapi.schematools.core.model.BrAPIObjectType;
import org.brapi.schematools.core.options.LinkType;
import org.brapi.schematools.core.options.OptionsTestBase;
import org.brapi.schematools.core.validiation.Validation;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@Slf4j
class BrAPISchemaReaderOptionsTest extends OptionsTestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.fasterxml.jackson.databind.ObjectWriter;
import org.brapi.schematools.core.markdown.options.MarkdownGeneratorOptions;
import org.brapi.schematools.core.options.OptionsTestBase;
import org.brapi.schematools.core.response.Response;
import org.brapi.schematools.core.validiation.Validation;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.brapi.schematools.core.options.OptionsTestBase;
import org.brapi.schematools.core.response.Response;
import org.brapi.schematools.core.validiation.Validation;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

class OntModelGeneratorOptionsTest extends OptionsTestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import lombok.extern.slf4j.Slf4j;
import org.brapi.schematools.core.model.BrAPIObjectProperty;
import org.brapi.schematools.core.model.BrAPIObjectType;
import org.brapi.schematools.core.options.LinkType;
Expand All @@ -21,6 +22,7 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@Slf4j
class OpenAPIGeneratorOptionsTest extends OptionsTestBase {

@BeforeEach
Expand All @@ -43,7 +45,7 @@ void loadJson() {
try {
options = OpenAPIGeneratorOptions.load(Path.of(ClassLoader.getSystemResource("OpenAPIGenerator/openapi-test-options.json").toURI()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
fail(e.getMessage());
}

Expand All @@ -59,7 +61,7 @@ void loadYaml() {
try {
options = OpenAPIGeneratorOptions.load(Path.of(ClassLoader.getSystemResource("OpenAPIGenerator/openapi-test-options.yaml").toURI()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
fail(e.getMessage());
}

Expand All @@ -75,7 +77,7 @@ void overwrite() {
try {
options = OpenAPIGeneratorOptions.load(Path.of(ClassLoader.getSystemResource("OpenAPIGenerator/openapi-override-options.yaml").toURI()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
fail(e.getMessage());
}

Expand Down Expand Up @@ -126,7 +128,7 @@ void compare() {

assertEquals(writer.writeValueAsString(options1), writer.writeValueAsString(options2));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
fail(e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.brapi.schematools.core.r;

import lombok.extern.slf4j.Slf4j;
import org.brapi.schematools.core.model.BrAPIClass;
import org.brapi.schematools.core.r.options.RGeneratorOptions;
import org.brapi.schematools.core.response.Response;
import org.brapi.schematools.core.utils.StringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import static org.brapi.schematools.core.test.TestUtils.assertMultilineEqual;
import static org.brapi.schematools.core.utils.StringUtils.isMultilineEqual;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@Slf4j
class RGeneratorTest {

@Test
void generate() {
Response<List<Path>> response = null;
try {
response = new RGenerator(RGeneratorOptions.load().setOverwrite(true), Paths.get("build/test-output/R/Generated"))
.generate(Path.of(ClassLoader.getSystemResource("BrAPI-Schema").toURI()));
} catch (Exception e) {
log.error(e.getMessage(), e);
Assertions.fail(e) ;
}

assertNotNull(response);

response.getAllErrors().forEach(this::printError);
assertFalse(response.hasErrors());

assertNotNull(response.getResult());

assertREquals(response.getResult()) ;
}

private void assertREquals(List<Path> result) {
try {
for (Path path : result) {

String rFile = path.getFileName().toString();

String expected = StringUtils.readStringFromPath(Path.of(ClassLoader.getSystemResource("RGenerator/Generated/"+ rFile).toURI())).getResultOrThrow();
String actual = StringUtils.readStringFromPath(path).getResultOrThrow();

if (!isMultilineEqual(expected, actual)) {
Path build = Paths.get("build/test-output/R/Fails", rFile);
Files.createDirectories(build.getParent());
Files.writeString(build, actual);
}

assertMultilineEqual(expected, actual);
}

} catch (Exception e) {
log.error(e.getMessage(), e);
Assertions.fail(e) ;
}
}

private void printError(Response.Error error) {
System.out.println(error.toString());
}
}
Loading
Loading