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 @@ -205,6 +205,9 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("cJSON.c.mustache", "external", "cJSON.c"));
supportingFiles.add(new SupportingFile("cJSON.h.mustache", "external", "cJSON.h"));

// Object files in model folder
supportingFiles.add(new SupportingFile("object-body.mustache", "model", "object.c"));
supportingFiles.add(new SupportingFile("object-header.mustache", "model", "object.h"));
}

@Override
Expand Down Expand Up @@ -333,6 +336,9 @@ public String toVarName(String name) {
@Override
public String toParamName(String name) {
// should be the same as variable name
if (name.matches("^\\d.*")) {
name = escapeReservedWord(name);
}
name = name.replaceAll("-","_");
return name;
}
Expand Down Expand Up @@ -412,11 +418,15 @@ public String toApiName(String name) {

@Override
public String toEnumValue(String value, String datatype) {
value = value.replaceAll("-","_");
if (isReservedWord(value)) {
value = escapeReservedWord(value);
}
if ("Integer".equals(datatype) || "Float".equals(datatype)) {
return value;
} else {
if (value.matches("\\d.*")) { // starts with number
return "N" + escapeText(value);
return escapeReservedWord(escapeText(value));
} else {
return escapeText(value);
}
Expand Down Expand Up @@ -444,7 +454,7 @@ public String toEnumVarName(String name, String datatype) {
enumName = enumName.replaceFirst("_$", "");

if (enumName.matches("\\d.*")) { // starts with number
return "N" + enumName;
return escapeReservedWord(enumName);
} else {
return enumName;
}
Expand All @@ -457,7 +467,7 @@ public String toEnumName(CodegenProperty property) {
enumName = enumName.replaceFirst("_$", "");

if (enumName.matches("\\d.*")) { // starts with number
return "N" + enumName;
return escapeReservedWord(enumName);
} else {
return enumName;
}
Expand Down Expand Up @@ -502,7 +512,10 @@ public String toApiImport(String name) {

@Override
public String toModelImport(String name) {
return "#include \"" +"../model/" + name + ".h\"";
if (importMapping.containsKey(name)) {
return "#include \"" +"../model/" + importMapping.get(name) + ".h\"";
} else
return "#include \"" +"../model/" + name + ".h\"";
}

@Override
Expand Down Expand Up @@ -595,6 +608,18 @@ public String escapeUnsafeCharacters(String input) {
return input.replace("=end", "=_end").replace("=begin", "=_begin");
}

@Override
public CodegenProperty fromProperty(String name, Schema p) {
CodegenProperty cm = super.fromProperty(name,p);
Schema ref = ModelUtils.getReferencedSchema(openAPI, p);
if (ref != null) {
if (ref.getEnum() != null) {
cm.isEnum = true;
}
}
return cm;
}


@Override
public void postProcessFile(File file, String fileType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sudo make install
```

## Compile the sample:
This will compile the generated code and create a library in build folder which has to be linked to the codes where API will be used.
```bash
mkdir build
cd build
Expand All @@ -51,15 +52,17 @@ make
sudo make install
```
## How to use compiled library
Considering the test/source code which uses the API is written in main.c(respective api include is written and all objects necessary are defined)
Considering the test/source code which uses the API is written in main.c(respective api include is written and all objects necessary are defined and created)

To compile main.c use following command
To compile main.c(considering the file is present in build folder) use following command
-L - locaiton of the library(not required if cmake with normal installation is performed)
-l library name
```bash
gcc main.c -L. -lpetstore -o main
```
once compile, you can run it with ``` ./main ```

Note: You dont need to specify includes for models and include folder seperately as they are path linked. You just have to import the api.h file in your code, the include linking will work.

## Author

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "object.h"

object_t *object_create() {
object_t *object = malloc(sizeof(object_t));

return object;
}

void object_free(object_t *object) {
free (object);
}

cJSON *object_convertToJSON(object_t *object) {
cJSON *item = cJSON_CreateObject();

return item;
fail:
cJSON_Delete(item);
return NULL;
}

object_t *object_parseFromJSON(char *jsonString){
object_t *object = NULL;

return object;
end:
return NULL;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* object.h
*/

#ifndef _object_H_
#define _object_H_

#include <string.h>
#include "../external/cJSON.h"
#include "../include/list.h"
#include "../include/keyValuePair.h"


typedef struct object_t {
void *temporary;
} object_t;

object_t *object_create();

void object_free(object_t *object);

object_t *object_parseFromJSON(char *jsonString);

cJSON *object_convertToJSON(object_t *object);

#endif /* _object_H_ */